Modifying Structure: Renaming Columns
How do we rename columns in a DataFrame?
Answer
We use df.rename(). The key parameter is columns=, which can take either:
a dictionary mapping
old_name : new_name, ora string function applied to every column name.
Example:
# Dict
df.rename(columns = {"Calories" : "Cal"})
# Str Function
df.rename(columns = str.lower)