以下代码来自
pandas/tseries/frequencies.py
导致我的代码崩溃:
if not self.is_monotonic or not self.index._is_unique:
return None
delta = self.deltas[0]
ppd = periods_per_day(self._creso)
if delta and _is_multiple(delta, ppd):
return self._infer_daily_rule()
# Business hourly, maybe. 17: one day / 65: one weekend
if self.hour_deltas in ([1, 17], [1, 65], [1, 17, 65]):
return "BH"
# Possibly intraday frequency. Here we use the
# original .asi8 values as the modified values
# will not work around DST transitions. See #8772
if not self.is_unique_asi8:
return None
第一个测试,
self.index._is_unique
,合格;第二,
not self.is_unique_asi8
,失败,然后返回
None
。
我看过
this issue
以及相应的PR,但是·
我的代码,它的当前形式,如下所示:
db = Database()
df, last_trade_time = db.fetch_trades()
# Convert the time column to a datetime object with the unit of seconds
df['time'] = pd.to_datetime(df['time'], unit='s')
# Localize the timestamps to UTC
df['time'] = df['time'].dt.tz_localize('UTC')
# Ensure uniqueness by adding the index as nanoseconds
df['time'] = df['time'] + pd.to_timedelta(df.index, unit='ns')
# Set DataFrame index
df.set_index('time', inplace=True)
dataset = PandasDataset(df, target="price")
这些
time
s以秒为单位,具有亚纳米精度(来自Kraken)。
我如何准备我的数据?这里只有一个月左右的Python经验。。。
我用另一种形式问了这个问题
here