1df.rename(columns={'oldName1': 'newName1',
2 'oldName2': 'newName2'},
3 inplace=True, errors='raise')
4# Make sure you set inplace to True if you want the change
5# to be applied to the dataframe
1import pandas as pd
2data = pd.read_csv(file)
3data.rename(columns={'original':'new_name'}, inplace=True)
1# Basic syntax:
2# Assign column names to a Pandas dataframe:
3pandas_dataframe.columns = ['list', 'of', 'column', 'names']
4# Note, the list of column names must equal the number of columns in the
5# dataframe and order matters
6
7# Rename specific column names of a Pandas dataframe:
8pandas_dataframe.rename(columns={'column_name_to_change':'new_name'})
9# Note, with this approach, you can specify just the names you want to
10# change and the order doesn't matter
11
12# For rows, use "index". E.g.:
13pandas_dataframe.index = ['list', 'of', 'row', 'names']
14pandas_dataframe.rename(index={'row_name_to_change':'new_name'})
1df.rename(columns={"old_col1": "new_col1", "old_col2": "new_col2"}, inplace=True)
1df = df.rename(columns={'oldName1': 'newName1', 'oldName2': 'newName2'})
2# Or rename the existing DataFrame (rather than creating a copy)
3df.rename(columns={'oldName1': 'newName1', 'oldName2': 'newName2'}, inplace=True)
4