0
0
Pandasdata~10 mins

Standardizing column names 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 convert all column names in the DataFrame to lowercase.

Pandas
df.columns = df.columns.[1]()
Drag options to blanks, or click blank then click option'
Atitle
Blower
Cupper
Dcapitalize
Attempts:
3 left
💡 Hint
Common Mistakes
Using upper() instead of lower() changes columns to uppercase.
Using title() or capitalize() changes only first letters, not all lowercase.
2fill in blank
medium

Complete the code to replace spaces in column names with underscores.

Pandas
df.columns = df.columns.str.[1](' ', '_')
Drag options to blanks, or click blank then click option'
Astrip
Bsplit
Creplace
Djoin
Attempts:
3 left
💡 Hint
Common Mistakes
Using strip() removes spaces only at start or end, not inside.
Using split() breaks strings into lists, not replacing characters.
3fill in blank
hard

Fix the error in the code to remove leading and trailing spaces from column names.

Pandas
df.columns = df.columns.str.[1]()
Drag options to blanks, or click blank then click option'
Astrip
Btrim
Cclean
Dremove
Attempts:
3 left
💡 Hint
Common Mistakes
Using trim() which is not a pandas string method.
Using clean() or remove() which do not exist for strings.
4fill in blank
hard

Fill both blanks to create a dictionary that maps old column names to lowercase names without spaces.

Pandas
new_names = {col: col.[1]().[2](' ', '_') for col in df.columns}
Drag options to blanks, or click blank then click option'
Alower
Breplace
Cstrip
Dupper
Attempts:
3 left
💡 Hint
Common Mistakes
Using upper() instead of lower() changes case wrongly.
Using strip() instead of replace() does not change spaces inside.
5fill in blank
hard

Fill all three blanks to rename columns by stripping spaces, converting to lowercase, and replacing spaces with underscores.

Pandas
df.columns = df.columns.str.[1]().str.[2]().str.[3](' ', '_')
Drag options to blanks, or click blank then click option'
Astrip
Blower
Creplace
Dupper
Attempts:
3 left
💡 Hint
Common Mistakes
Changing order of methods can cause errors.
Using upper() instead of lower() changes case wrongly.