Answers for "Pandas rename columns by position"

0

rename one dataframe column python in inplace

import pandas as pd

d1 = {'Name': ['Pankaj', 'Lisa', 'David'], 'ID': [1, 2, 3], 'Role': ['CEO', 'Editor', 'Author']}

df = pd.DataFrame(d1)

print('Source DataFrame:\n', df)

df.rename(index={0: '#0', 1: '#1', 2: '#2'}, columns={'Name': 'EmpName', 'ID': 'EmpID', 'Role': 'EmpRole'}, inplace=True)

print('Source DataFrame:\n', df)
Posted by: Guest on May-30-2021
0

Pandas rename columns by position

df.rename(columns={ df.columns[1]: "your value" }, inplace = True)
Posted by: Guest on August-27-2021

Code answers related to "Pandas rename columns by position"

Python Answers by Framework

Browse Popular Code Answers by Language