我有一个数据框,其中包含无用的列名,我想将其转换为日期时间。当前列名是
Index([Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median, Market Median], dtype=object)
我试图将它们变成日期时间名称
cols = pd.date_range(start='2004-02-28', end='2013-05-31', freq='Q-NOV')
df.columns = cols
但我得到了错误
Exception: Reindexing only valid with uniquely valued Index objects
cols
似乎是一个有效的索引:
<class 'pandas.tseries.index.DatetimeIndex'>
[2004-02-29 00:00:00, ..., 2013-05-31 00:00:00]
Length: 38, Freq: Q-NOV, Timezone: None
所以我不确定这个问题。我也不认为需要用唯一对象命名列,因此我正在尝试做的事情可能存在更根本的问题。
谢谢你的尽心帮助。