pandas.DataFrame Resets an instance of the index name in Python

  • 2021-01-25 07:35:53
  • OfStack

Example:

Create DataFrame


###  The import module 
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
 
test = pd.DataFrame({'a':[11,22,33],'b':[44,55,66]})
"""
  a  b
0 11 44
1 22 55
2 33 66
"""

Change the column name method 1: rename


test.rename(columns={'a':'c'},inplace=True)
"""
  c  b
0 11 44
1 22 55
2 33 66
""""

Change listed method 2: direct assignment


test.columns = ['c','b']

Related articles: