df.rename(columns={ df.columns[1]: "your value" }, inplace = True)
df.columns = ['new_col1', 'new_col2', 'new_col3', 'new_col4']
import pandas as pd
d1 = {'Name': ['Pankaj', 'Lisa', 'David'], 'ID': [1, 2, 3], 'Role': ['CEO', 'Editor', 'Author']}
df = pd.DataFrame(d1)
print('Source DataFrame:
', df)
df.rename(index={0: '#0', 1: '#1', 2: '#2'}, columns={'Name': 'EmpName', 'ID': 'EmpID', 'Role': 'EmpRole'}, inplace=True)
print('Source DataFrame:
', df)
df2.columns = stocks['Ticker'][:3]
[:3] is just use first 3
[5::] skip first 5
price price price
2021-01-11 131.90 15.00 179.07
2021-01-12 128.09 15.74 182.65
to
Ticker A AAL AAP
2021-01-11 131.90 15.00 179.07
2021-01-12 128.09 15.74 182.65