Pandas DataFrame rename 修改列名添加后缀

环境信息

  • ModelArts
    • Notebook - Multi-Engine 2.0 (python3)
      • JupyterLab - Notebook - Conda-python3
        • pandas 0.22.0

Pandas DataFrame rename 列名添加后缀

df = pd.DataFrame(np.random.randint(100,size=(10,10)))
df

# 修改列名
# inplace=True 修改原来的,不生成副本
df.rename(columns=lambda x:str(x)+"_mean", inplace=True)
df

help

help(df.rename)

Help on method rename in module pandas.core.frame:

rename(mapper=None, index=None, columns=None, axis=None, copy=True, inplace=False, level=None) method of pandas.core.frame.DataFrame instance
    Alter axes labels.
    
    Function / dict values must be unique (1-to-1). Labels not contained in
    a dict / Series will be left as-is. Extra labels listed don't throw an
    error.
    
    See the :ref:`user guide <basics.rename>` for more.

......    

备注

  1. 欢迎各位同学一起来交流学习心得^_^
  2. 在线课程、沙箱实验、认证、论坛和直播,其中包含了许多优质的内容,推荐了解与学习。
(完)