我想根据日期在另一个数据框中搜索一个值(来自一个数据框)。
我有一个基于 1 分钟频率的 DatetimeIndex 数据框。我将 Dataframe 重新采样为 5 分钟和每天的频率。这是代码和输出:
agg_dict = {'open': 'first','high': 'max','low': 'min','cls': 'last','vol': 'sum'}
data_5min = data_rth.resample('5min').agg(agg_dict).dropna().round(2).sort_index(ascending=False)
data_daily = data_rth.resample('D').agg(agg_dict).dropna().round(2).sort_index(ascending=False)
data_weekly= data_rth.resample('W').agg(agg_dict).dropna().round(2).sort_index(ascending=False)
data_monthly= data_rth.resample('M').agg(agg_dict).dropna().round(2).sort_index(ascending=False)
print('data_daily','\n',data_daily['high'].head())
print('data_5min','\n',data_5min['high'].head(24))
output:
data_daily
time
2021-08-05 441.85
2021-08-04 441.12
2021-08-03 441.28
2021-08-02 440.93
2021-07-30 440.06
Name: high, dtype: float64
data_5min
time
2021-08-05 16:00:00 441.85
2021-08-05 15:55:00 441.65
2021-08-05 15:50:00 441.39
2021-08-05 15:45:00 441.23
2021-08-05 15:40:00 441.24
2021-08-05 15:35:00 441.11
2021-08-05 15:30:00 440.90
2021-08-05 15:25:00 440.83
2021-08-05 15:20:00 440.78
2021-08-05 15:15:00 440.86
2021-08-05 15:10:00 440.94
2021-08-05 15:05:00 440.96
2021-08-05 15:00:00 440.89
2021-08-05 14:55:00 440.83
2021-08-05 14:50:00 440.87
2021-08-05 14:45:00 440.88
2021-08-05 14:40:00 440.96
2021-08-05 14:35:00 440.88
2021-08-05 14:30:00 440.86
2021-08-05 14:25:00 440.91
2021-08-05 14:20:00 440.96
2021-08-05 14:15:00 440.96
2021-08-05 14:10:00 440.98
2021-08-05 14:05:00 441.12
Name: high, dtype: float64
我现在想看看每天的高潮在 5 分钟帧中显示的位置。我试过了
data_5min['high'].isin(data_daily['high'])
what gives me this output:
time
2021-08-05 16:00:00 True
2021-08-05 15:55:00 False
2021-08-05 15:50:00 False
2021-08-05 15:45:00 False
2021-08-05 15:40:00 False
2021-08-05 15:35:00 False
2021-08-05 15:30:00 False
2021-08-05 15:25:00 False
2021-08-05 15:20:00 False
2021-08-05 15:15:00 False
2021-08-05 15:10:00 False
2021-08-05 15:05:00 False
2021-08-05 15:00:00 False
2021-08-05 14:55:00 False
2021-08-05 14:50:00 False
2021-08-05 14:45:00 False
2021-08-05 14:40:00 False
2021-08-05 14:35:00 False
2021-08-05 14:30:00 False
2021-08-05 14:25:00 False
2021-08-05 14:20:00 False
2021-08-05 14:15:00 False
2021-08-05 14:10:00 False
2021-08-05 14:05:00 True
最后一行中的 True 我不想要。这似乎是 data_daily 索引 2021-08-04 的值。我想要的是在 data_5min 中搜索 data_daily 中的每个值,但取决于日期。我试过了
data_5min['high'].isin(data_daily['high']) & data_5min.index.isin(data_daily.index.date)
但我不让它工作。
你能帮忙的话,我会很高兴。