0
0
Pandasdata~5 mins

Selecting multiple columns in Pandas - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
How do you select multiple columns from a pandas DataFrame?
You select multiple columns by passing a list of column names inside double square brackets, like df[["col1", "col2"]].
Click to reveal answer
beginner
What type of object is returned when selecting multiple columns from a DataFrame?
Selecting multiple columns returns a new DataFrame containing only those columns.
Click to reveal answer
intermediate
What happens if you select a single column using double square brackets, like df[["col1"]]?
You get a DataFrame with one column, not a Series. Single square brackets return a Series, double brackets return a DataFrame.
Click to reveal answer
intermediate
Can you select columns by position using the same method as selecting by name?
No, selecting by position uses df.iloc, while selecting by name uses df[[...]].
Click to reveal answer
beginner
Why might you want to select multiple columns from a DataFrame?
To focus analysis on specific data, reduce memory use, or prepare data for visualization or modeling.
Click to reveal answer
Which syntax correctly selects columns 'A' and 'B' from DataFrame df?
Adf[['A', 'B']]
Bdf['A', 'B']
Cdf.loc['A', 'B']
Ddf.iloc['A', 'B']
What type of object is returned by df[['A', 'B']]?
ADataFrame
BSeries
CList
DDictionary
How do you select columns by position instead of name?
Adf[['0', '1']]
Bdf.iloc[:, [0, 1]]
Cdf.select([0, 1])
Ddf.loc[0, 1]
What does df[['A']] return?
AAn error
BA Series
CA list
DA DataFrame with one column
Why is selecting multiple columns useful?
ATo change data types
BTo delete data
CTo focus on specific data for analysis
DTo rename columns
Explain how to select multiple columns from a pandas DataFrame and what the result looks like.
Think about how you pick multiple items from a list.
You got /2 concepts.
    Describe the difference between selecting a single column with single brackets and double brackets in pandas.
    Consider the type of object returned.
    You got /2 concepts.