0
0
Pandasdata~10 mins

Renaming columns 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 rename the column 'old' to 'new' in the DataFrame df.

Pandas
df.rename(columns=[1], inplace=True)
Drag options to blanks, or click blank then click option'
A{'old': 'new'}
B['old', 'new']
C('old', 'new')
D'old:new'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list or tuple instead of a dictionary.
Passing a string instead of a dictionary.
2fill in blank
medium

Complete the code to rename multiple columns: 'A' to 'Alpha' and 'B' to 'Beta'.

Pandas
df.rename(columns=[1], inplace=True)
Drag options to blanks, or click blank then click option'
A'A:Alpha, B:Beta'
B['A', 'Alpha', 'B', 'Beta']
C{'A': 'Alpha', 'B': 'Beta'}
D('A', 'Alpha', 'B', 'Beta')
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list or tuple instead of a dictionary.
Forgetting to set inplace=True to modify the DataFrame.
3fill in blank
hard

Fix the error in the code to rename column 'score' to 'points' without changing the original DataFrame.

Pandas
new_df = df.rename(columns=[1])
Drag options to blanks, or click blank then click option'
A('score', 'points')
B['score', 'points']
C'score:points'
D{'score': 'points'}
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a list or tuple instead of a dictionary.
Using inplace=True which modifies the original DataFrame.
4fill in blank
hard

Fill both blanks to rename columns 'x' to 'X' and 'y' to 'Y' and assign the result to df_new.

Pandas
df_new = df.rename(columns=[1], inplace=[2])
Drag options to blanks, or click blank then click option'
A{'x': 'X', 'y': 'Y'}
BTrue
CFalse
D{'X': 'x', 'Y': 'y'}
Attempts:
3 left
💡 Hint
Common Mistakes
Setting inplace=True which modifies the original DataFrame.
Using the wrong dictionary mapping.
5fill in blank
hard

Fill all three blanks to rename columns 'a' to 'alpha', 'b' to 'beta', and 'c' to 'gamma' and save the result in df2 without changing df.

Pandas
df2 = df.rename(columns=[1], inplace=[2], errors=[3])
Drag options to blanks, or click blank then click option'
A{'a': 'alpha', 'b': 'beta', 'c': 'gamma'}
BFalse
C'ignore'
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Setting inplace=True which modifies the original DataFrame.
Not handling errors when columns might be missing.