📜  如何重命名 Pandas DataFrame 中的列 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:21.215000             🧑  作者: Mango

代码示例6
# import pandas library
import pandas as pd

# create pandas DataFrame
df = pd.DataFrame({'team': ['India', 'South Africa', 'New Zealand', 'England'],
                   'points': ['10', '8', '3', '5'],
                   'runrate': ['0.5', '1.4', '2', '-0.6'],
                   'wins': ['5', '4', '2', '2']})

# print the column names of DataFrame
print(list(df))

# rename the column names of DataFrame
df.rename(columns={'points': 'total_points',
          'runrate': 'run_rate'}, inplace=True)

# print the new column names of DataFrame
print(list(df))