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?✗ Incorrect
df.columns returns the labels of the columns in the DataFrame.
Which attribute gives you the row labels in a pandas DataFrame?
✗ Incorrect
df.index holds the row labels of the DataFrame.
If you want to rename the columns of a DataFrame, which attribute would you assign new values to?
✗ Incorrect
Assigning a new list to df.columns changes the column names.
What type of object do
df.columns and df.index return?✗ Incorrect
Both df.columns and df.index return a pandas Index object.
Can the
index attribute contain non-numeric labels?✗ Incorrect
The index can have any hashable labels like strings, dates, or numbers.
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.