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'})
1print(df.rename(columns={'A': 'a', 'C': 'c'}))
2# a B c
3# ONE 11 12 13
4# TWO 21 22 23
5# THREE 31 32 33
6