【发布时间】:2016-12-27 23:50:30
【问题描述】:
(我认为)我有一个数据集,其中的列代表 datetime 间隔
列在日期时间中转换为:
for col in df.columns:
df.rename({col: pd.to_datetime(col, infer_datetime_format=True)}, inplace=True)
然后,我需要使用mean 将列(年和月'2001-01')分成季度
我试过了
df = df.resample('1q', how='mean', axis=1)
DataFrame 也有一个多索引集 ['RegionName', 'County']
但我得到了错误:
Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'Index'
问题出在to_datetime函数还是错误采样?
【问题讨论】:
-
您可以发布数据框的前几行吗?根据您提供的信息,
df.rename语句应该会失败。