Challenge - 5 Problems
Column Renaming Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of renaming columns with a dictionary
What is the output DataFrame after renaming columns using the given dictionary?
Data Analysis Python
import pandas as pd df = pd.DataFrame({ 'A': [1, 2], 'B': [3, 4], 'C': [5, 6] }) new_df = df.rename(columns={'A': 'X', 'B': 'Y'}) print(new_df)
Attempts:
2 left
💡 Hint
Check which columns are renamed and which remain unchanged.
✗ Incorrect
The rename method changes only the columns specified in the dictionary. Columns 'A' and 'B' become 'X' and 'Y'. Column 'C' stays the same.
❓ data_output
intermediate2:00remaining
Result of renaming columns with inplace=True
What is the DataFrame after renaming columns with inplace=True?
Data Analysis Python
import pandas as pd df = pd.DataFrame({ 'one': [10, 20], 'two': [30, 40] }) df.rename(columns={'one': 'first', 'two': 'second'}, inplace=True) print(df)
Attempts:
2 left
💡 Hint
inplace=True changes the original DataFrame.
✗ Incorrect
Using inplace=True modifies the original DataFrame columns directly.
🔧 Debug
advanced2:00remaining
Identify the error in renaming columns code
What error does this code raise when trying to rename columns?
Data Analysis Python
import pandas as pd df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]}) new_df = df.rename(columns=['A', 'B'])
Attempts:
2 left
💡 Hint
Check the expected type for the columns parameter in rename.
✗ Incorrect
The rename method expects a dictionary or callable for columns, not a list.
🚀 Application
advanced2:00remaining
Rename columns using a function
Which option correctly renames all columns to uppercase using a function?
Data Analysis Python
import pandas as pd df = pd.DataFrame({ 'name': ['Alice', 'Bob'], 'age': [25, 30] }) new_df = df.rename(columns=??? ) print(new_df)
Attempts:
2 left
💡 Hint
The columns parameter can accept a function applied to each column name.
✗ Incorrect
Passing str.upper applies the function to each column name to rename them.
🧠 Conceptual
expert2:00remaining
Effect of renaming columns on DataFrame indexing
After renaming columns in a DataFrame, which statement is true about the DataFrame's index?
Attempts:
2 left
💡 Hint
Think about what columns and index represent separately.
✗ Incorrect
Renaming columns only changes column labels, not the row index.