添加字符串结束列名称数据帧

时间:2017-05-19 17:32:38

标签: pandas

我有以下df:

                             BRET          CRET           NET
SEEN                          4             4              5       
NOT SEEN                      5             9              9          
DELETED                       9            14             13        

我想在每个列标题中添加一个字符串。

所需的输出如下所示:

                        BRET :this M      CRET : past M   NET : past 2 M
SEEN                          4             4              5       
NOT SEEN                      5             9              9          
DELETED                       9            14             13 

问题是我不想重命名列,只是在列名末尾添加字符串

这可能吗?

1 个答案:

答案 0 :(得分:1)

是的,您可以使用.values:

df.columns.values[0] = df.columns.values[0] + ' :this M'
df.columns.values[1] = df.columns.values[1] + ' : past M'
df.columns.values[2] = df.columns.values[2] + ' : past 2 M'

输出:

          BRET: this M  CRET : past M  NET : past 2 M
SEEN                 4              4               5
NOT SEEN             5              9               9
DELETED              9             14              13