无法重命名列序列

2024-09-29 21:29:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我无法重命名系列的列:

tabla_paso4

Date            decay
2015-06-29    0.003559
2015-09-18    0.025024
2015-08-24    0.037058
2014-11-20    0.037088
2014-10-02    0.037098
Name: decay, dtype: float64

我试过:

^{pr2}$

我已经看过可能的复制品,但是不知道为什么尽管申请了:

tabla_paso4.rename(columns={'decay':'decay_acumul'},inplace=True)

返回如下序列:

Date
2015-06-29    0.003559
2015-09-18    0.025024
2015-08-24    0.037058
2014-11-20    0.037088
2014-10-02    0.037098
dtype: float64

Tags: columnsnametruedate重命名renamedtype复制品
2条回答

试试看

tabla_paso4.columns = ['Date', 'decay_acumul']

或者

^{pr2}$

您之前做错的是,您错过了inplace=True部分,因此重命名的df被返回,但没有被赋值。在

我希望这有帮助!在

看起来你的tabla_paso4-是一个序列,而不是一个数据帧。在

您可以从中生成带有命名列的数据帧:

new_df = tabla_paso4.to_frame(name='decay_acumul')

相关问题 更多 >

    热门问题