Wybieranie kolumn po nazwie
Pojedyncze kolumny i listy kolumn
Wybieranie kolumn po nazwie to bezpłatna lekcja Data Science Academy na CoddyKit. To lekcja 1 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Data Science Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Data Science Academy zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
Columns Are Your Starting Point
Real datasets have dozens of columns, but you rarely need them all. Picking the right columns by name is the first move in almost every analysis. 🎯
Grab One Column
To pull a single column, put its name in square brackets after the DataFrame. What you get back is a one-dimensional Series.
ages = df["age"]
print(ages.head())A Single Column Is a Series
One bracketed name returns a Series: a single labeled column, not a table. It keeps the same index as the DataFrame it came from.
type(df["age"])
# pandas.core.series.SeriesDot Access as a Shortcut
You can also reach a column with dot access, like df.age. It is shorter, but only works when the name has no spaces or symbols.
df.age # same as df["age"]When Dot Access Fails
Dot access breaks on names with spaces, like df.user name, or names that clash with methods. When in doubt, prefer bracket access for safety.
df["user name"] # brackets handle spacesSelect Several Columns
Pass a list of names inside the brackets to grab many columns at once. Notice the double square brackets in the syntax.
subset = df[["name", "age", "city"]]A Column List Is a DataFrame
Selecting a list of names returns a DataFrame, even if the list holds just one name. That is the key difference from single-bracket access.
df[["age"]] # DataFrame, not SeriesOrder Is Up to You
The columns appear in the exact order you list them, not their original order. This is a quick way to rearrange a table for a report.
df[["city", "name"]] # city first nowSelecting Many With loc
The loc accessor selects by label and lets you choose rows and columns together. A colon means all rows.
df.loc[:, ["name", "age"]]List All Column Names
Forgot the exact spelling? The columns attribute lists every name, so you can copy them without typos.
print(df.columns.tolist())Watch the KeyError
Ask for a name that does not exist and pandas raises a KeyError. Names are case-sensitive, so Age and age are different.
df["Age"] # KeyError if column is "age"Quick Check
Think about what each bracket style returns.
Recap: Picking Columns
Single brackets give a Series, a list of names gives a DataFrame in your chosen order, and loc selects by label. You now grab exactly the columns you need. ✅
Często zadawane pytania
Czy lekcja „Wybieranie kolumn po nazwie” jest bezpłatna?
Tak — pełny tekst „Wybieranie kolumn po nazwie” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Data Science Academy, przejdź na CoddyKit PRO. Kurs Data Science Academy zawiera 4 lekcji w sumie.
Co nauczysz się w „Wybieranie kolumn po nazwie”?
Pojedyncze kolumny i listy kolumn Ćwiczysz Data Science Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Data Science Academy?
Nie wymagamy żadnego doświadczenia. Data Science Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 1 z 4.
Ile czasu zajmuje lekcja „Wybieranie kolumn po nazwie”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Data Science Academy?
Tak. Każda lekcja Data Science Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Wybieranie kolumn po nazwie
- Filtrowanie wierszy za pomocą warunków
- Łączenie filtrów za pomocą AND i OR
- query i isin do przejrzystego filtrowania