【发布时间】:2026-01-16 06:05:01
【问题描述】:
upper_lower_bound 从我的数据框中返回 2 个日期时间索引。我一次只使用一个,它们之间没有任何关系。
我想从数据帧 highP 中获取前 6 行数据的 max() 值,但如果我尝试从中减去 6,则会出现错误。 dt.timedelta(6) 从 df 中减去 6 天,但 df 中缺少天数,因此无法提供正确答案。
我如何对highP 进行切片,以便它为我提供该系列中的前六个值。
highP.loc[i - 6: i].max() 假设 i 是日期时间索引?
任何帮助将不胜感激!
upper_lower_bound = df[(isoHL['IH'] >= 1) | (isoHL['IL'] >= 1)].index[-3:-1]
if isoHL.loc[upper_lower_bound[-1]]['IH'] == 1 and isoHL.loc[upper_lower_bound[-1]]['IL'] == 0:
upper_bound = highP.loc[upper_lower_bound[-1] - dt.timedelta(6):upper_lower_bound[-1]].max()
else:
pass
【问题讨论】:
标签: python pandas numpy dataframe series