0
0
Pandasdata~5 mins

columns and index attributes in Pandas - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the columns attribute in a pandas DataFrame represent?
The columns attribute shows the labels of all the columns in the DataFrame. It is like the names on top of each column.
Click to reveal answer
beginner
What is the purpose of the index attribute in a pandas DataFrame?
The index attribute holds the labels for the rows. It helps to identify each row uniquely, like row numbers or custom labels.
Click to reveal answer
beginner
How can you access the column names of a DataFrame named df?
You can get the column names by using df.columns. It returns an Index object with all column labels.
Click to reveal answer
beginner
How do you get the row labels of a DataFrame named df?
Use df.index to get the row labels. It returns an Index object with all row labels.
Click to reveal answer
intermediate
Can the index and columns attributes be changed after creating a DataFrame?
Yes, both index and columns can be changed by assigning new labels. For example, df.columns = ['A', 'B'] changes column names.
Click to reveal answer
What does df.columns return in pandas?
AThe data types of columns
BThe list of row labels
CThe list of column labels
DThe number of rows
Which attribute gives you the row labels in a pandas DataFrame?
Adf.index
Bdf.shape
Cdf.values
Ddf.columns
If you want to rename the columns of a DataFrame, which attribute would you assign new values to?
Adf.columns
Bdf.index
Cdf.values
Ddf.rename
What type of object do df.columns and df.index return?
AList
BIndex object
CDictionary
DTuple
Can the index attribute contain non-numeric labels?
AOnly boolean values are allowed
BNo, only numbers are allowed
COnly dates are allowed
DYes, it can have strings or other labels
Explain what the columns and index attributes represent in a pandas DataFrame.
Think about how you name rows and columns in a table.
You got /3 concepts.
    How can you change the column names and row labels of a pandas DataFrame?
    Consider assigning new values directly to attributes.
    You got /3 concepts.