Pick Columns by Name
Single columns and column lists.
Pick Columns by Name is a free Data Science Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Data Science Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
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. ✅
Frequently asked questions
Is the “Pick Columns by Name” lesson free?
Yes — the full text of “Pick Columns by Name” is free to read here on the web, and the Data Science Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Data Science Academy course, upgrade to CoddyKit PRO.
What will I learn in “Pick Columns by Name”?
Single columns and column lists. You practise Data Science Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Data Science Academy?
No prior experience is required. Data Science Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Pick Columns by Name” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Data Science Academy lesson?
Yes. Every Data Science Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.