我试图在dataframe中比较不同的时间戳,并在时间差异大于一分钟时打印输出,这是我试图运行的代码:for e in TestDF['date']:
delta = TestDF.date.iloc[e+1] - TestDF.date.iloc[e]
if delta > datetime.timedelta(minutes=1):
print(TestDF.date.iloc[e+1])
print(TestDF.date.iloc[e])
这是我得到的错误:
ValueError : cannot add integral value to Timestamp without freq.
但这有效:TimeDifference = TestDF.date.iloc[4]-TestDF.date.iloc[3]
if TimeDifference == datetime.timedelta(minutes=1):
print(TimeDifference)
输出:0 days 00:01:00
任何帮助将不胜感激。
以下是一些例子数据:date open high low close
0 2020-01-28 07:00:00 311.83 311.89 311.62 311.81
1 2020-01-28 07:01:00 311.80 311.98 311.80 311.85
2 2020-01-28 07:02:00 311.90 312.00 311.88 311.98
3 2020-01-28 07:03:00 312.00 312.02 311.99 311.99
4 2020-01-28 07:04:00 312.00 312.00 311.91 311.91