gpt4 book ai didi

python - 将数据帧与 Pandas 连接后如何添加索引?

转载 作者:行者123 更新时间:2023-12-04 07:31:16 25 4
gpt4 key购买 nike

我连接文件并尝试重命名列。但它向我展示了错误。如果我想在连接后添加索引,我应该如何修复代码?

total = [df01,df02,df03,df04,df05,df06,df07,df08,df09,df10,df11,df12,df13,df14,df15]
date_count = pd.concat(total, axis=0)
date_count
第一个输出
                        new_sentiment
date new_sentiment
2020-03-06 POSITIVE 1
2020-03-17 NEGATIVE 1
NEUTRAL 1
2020-03-18 NEUTRAL 1
2020-03-23 NEUTRAL 1
... ... ...
2021-05-30 NEGATIVE 89
POSITIVE 13
2021-05-31 NEGATIVE 13
NEUTRAL 11
POSITIVE 2
760 rows × 1 columns
date_count.columns(['date','new_sentiment','count'])
第二个输出
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-174-57eb7952ea0a> in <module>
----> 1 date_count.columns(['date','new_sentiment','count'])

TypeError: 'Index' object is not callable

最佳答案

This ?
date_count.columns=['date']
date_count.rename_axis(index=['date','new_sentiment'])

关于python - 将数据帧与 Pandas 连接后如何添加索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67918946/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com