0
0
Pandasdata~10 mins

columns and index attributes in Pandas - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Akeys
Bindex
Cvalues
Dcolumns
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'index' instead of 'columns' to get column names.
Trying to use a method instead of an attribute.
2fill in blank
medium

Complete 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'
Aindex
Baxes
Ccolumns
Dkeys
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'columns' when trying to get row labels.
Using methods like keys() which do not return index labels.
3fill in blank
hard

Fix 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'
Avalues
Bindex
Ccolumns
Dkeys
Attempts:
3 left
💡 Hint
Common Mistakes
Adding parentheses after columns causing a TypeError.
Confusing attributes with methods.
4fill in blank
hard

Fill 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'
Aindex
Bvalues
Ccolumns
Dkeys
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping index and columns in the tuple.
Using values or keys which do not return labels.
5fill in blank
hard

Fill 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'
Aindex
B0
Ccolumns
Dvalues
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.