美文网首页
pandas 重命名列

pandas 重命名列

作者: 黑曼巴yk | 来源:发表于2019-12-10 13:54 被阅读0次

    rename

    重命名指定列名

    ufo.rename(columns={'Colors Reported':'Colors_Reported'},inplace=True )
    

    重命名全部列名

    ufo_col = ['city', 'Colors_Reported', 'ShapeReported', 'State', 'Time']
    ufo.columns = ufo_col
    ufo.head()
    

    初始化的时候同时重命名

    names = ['city', 'Colors_Reported', 'ShapeReported', 'State', 'Time']
    ufo = pd.read_csv('./pandas-videos/data/ufo.csv', names=names, header=0)
    ufo.head()
    

    使用正则表达式批量更改列名

    ufo.columns = ufo.columns.str.replace(' ','_')
    ufo.columns
    

    相关文章

      网友评论

          本文标题:pandas 重命名列

          本文链接:https://www.haomeiwen.com/subject/xjxggctx.html