【发布时间】:2016-04-20 09:55:57
【问题描述】:
我有一个数据框:
Seasonal
Date
2014-12 -1.089744
2015-01 -0.283654
2015-02 0.158974
2015-03 0.461538
我在DataFrame中使用了pd.to_period,所以它的索引变成了Pandas period类型(type 'pandas._period.Period')。
现在,我想将该索引转换为字符串。我正在尝试应用以下内容:
df.index=df.index.astype(str)
但是这不起作用...
ValueError: Cannot cast PeriodIndex to dtype |S0
我的代码从那时起就被冻结了。
求救
【问题讨论】:
-
df.index.strftime('%Y-%m')会为您工作吗? -
将此添加为答案
标签: python pandas data-structures