【pandas】pandas.DataFrame.rename()---重置索引名称

官方文档

github地址

 

例子:

  • 创建DataFrame
  1 ### 导入模块
  2 import numpy as np
  3 import pandas as pd
  4 import matplotlib.pyplot as plt
  5 
  6 test = pd.DataFrame({'a':[11,22,33],'b':[44,55,66]})
  7 """
  8     a   b
  9 0  11  44
 10 1  22  55
 11 2  33  66
 12 """
 
  • 更改列名方法一:rename
  1 test.rename(columns={'a':'c'},inplace=True)
  2 """
  3     c   b
  4 0  11  44
  5 1  22  55
  6 2  33  66
  7 """"
 
  • 更改列明方法二:直接赋值
test.columns = ['c','b']
posted @ 2018-04-04 15:34  wanglei5205  阅读(11273)  评论(0编辑  收藏  举报
levels of contents