0
0
Data Analysis Pythondata~10 mins

Renaming columns in Data Analysis Python - 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_name' to 'new_name' using pandas.

Data Analysis Python
df = df.rename(columns=[1])
Drag options to blanks, or click blank then click option'
A{'old_name': 'new_name'}
B['old_name', 'new_name']
C'old_name': 'new_name'
D('old_name', 'new_name')
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list or tuple instead of a dictionary.
Not wrapping the mapping in curly braces.
2fill in blank
medium

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

Data Analysis Python
df = df.rename(columns=[1])
Drag options to blanks, or click blank then click option'
A{'Alpha': 'A', 'Beta': 'B'}
B{'A': 'Alpha', 'B': 'Beta'}
C['A', 'Alpha', 'B', 'Beta']
D('A', 'Alpha', 'B', 'Beta')
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping keys and values in the dictionary.
Using a list or tuple instead of a dictionary.
3fill in blank
hard

Fix the error in the code to rename the column 'score' to 'points'.

Data Analysis Python
df.rename(columns=[1], inplace=True)
Drag options to blanks, or click blank then click option'
A('score', 'points')
B{'points': 'score'}
C['score', 'points']
D{'score': 'points'}
Attempts:
3 left
💡 Hint
Common Mistakes
Reversing the key-value order in the dictionary.
Using a list or tuple instead of a dictionary.
4fill in blank
hard

Fill both blanks to rename columns 'x' to 'X' and 'y' to 'Y', and assign the result to a new DataFrame.

Data Analysis Python
new_df = df.[1](columns=[2])
Drag options to blanks, or click blank then click option'
Arename
Bdrop
C{'x': 'X', 'y': 'Y'}
D{'X': 'x', 'Y': 'y'}
Attempts:
3 left
💡 Hint
Common Mistakes
Using drop instead of rename.
Swapping keys and values in the dictionary.
5fill in blank
hard

Fill all three blanks to rename columns 'a' to 'alpha', 'b' to 'beta', and only keep rows where 'alpha' is greater than 10.

Data Analysis Python
df_renamed = df.[1](columns=[2])
filtered_df = df_renamed[df_renamed[[3]] > 10]
Drag options to blanks, or click blank then click option'
Arename
B{'a': 'alpha', 'b': 'beta'}
C'alpha'
D'a'
Attempts:
3 left
💡 Hint
Common Mistakes
Filtering using the old column name 'a' instead of 'alpha'.
Swapping keys and values in the rename dictionary.