Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to get the column names of the DataFrame.
Pandas
column_names = df.[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'index' instead of 'columns' to get column names.
Trying to use a method instead of an attribute.
✗ Incorrect
The columns attribute returns the column labels of the DataFrame.
2fill in blank
mediumComplete the code to get the index labels of the DataFrame.
Pandas
row_labels = df.[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'columns' when trying to get row labels.
Using methods like
keys() which do not return index labels.✗ Incorrect
The index attribute returns the row labels of the DataFrame.
3fill in blank
hardFix the error in the code to access the DataFrame's columns attribute correctly.
Pandas
cols = df.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Adding parentheses after
columns causing a TypeError.Confusing attributes with methods.
✗ Incorrect
The columns attribute is not a method, so it should not have parentheses.
4fill in blank
hardFill both blanks to get the index and columns of the DataFrame as a tuple.
Pandas
info = (df.[1], df.[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping
index and columns in the tuple.Using
values or keys which do not return labels.✗ Incorrect
The index attribute gives row labels, and columns gives column names.
5fill in blank
hardFill all three blanks to create a dictionary with keys as column names and values as index labels.
Pandas
mapping = {col: df.[1][[2]] for col in df.[3] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
values instead of index for row labels.Using string '0' instead of integer 0 for indexing.
Swapping
columns and index.✗ Incorrect
This creates a dictionary where each column name maps to the first index label (position 0).