【发布时间】:2020-12-08 23:36:39
【问题描述】:
我正在尝试对 pandas 中的 DateTime 系列进行重新采样,如下所示:
df = pd.read_csv(pathToParam + "/" + file)
df.drop(["LAT", "LON", "STATION_HEIGHT"], axis = 1, inplace=True)
df.set_index(df.DATE, inplace=True, drop=True)
if granularity == "daily":
df.index = pd.to_datetime(df.index, cache=False)
df = df.sort_index()
df = df.resample("8H", closed="right").bfill()
Dataframe 如下所示:
| DATE | STATION_ID | CLOUD_COVER_TOTAL |
|---|---|---|
| 2016-01-01 | 1048 | 6.7 |
| 2016-01-02 | 1048 | 7.8 |
| 2016-01-03 | 1048 | 7.8 |
但我总是得到这个错误:
ValueError: index must be monotonic increasing or decreasing
我尝试了parse_dates = True 并在各种平台上搜索了可能的解决方案,但仍然一无所获。请帮忙。
【问题讨论】:
-
一些想法 - 你使用最后一个熊猫版本吗?某些日期时间是否可能重复?
-
@jezrael - pandas 是 1.1.4,不能有任何重复
-
如果测试删除
closed="right"仍然错误? -
是的,还是一样
-
无法模拟,我工作得很好。