Python 使用一个数据帧输出在另一个数据帧中查找匹配行

Python 使用一个数据帧输出在另一个数据帧中查找匹配行,python,pandas,dataframe,Python,Pandas,Dataframe,我想使用一个数据帧中的一些日常数据作为限定符,在另一个数据帧中运行一些代码。两个数据帧都包含['Date'、'Time'、'Ticker'、'Open'、'High'、'Low'、'Close']。一个数据帧只有每日信息,另一个包含5分钟的相同字段,下面是一些示例 打印(df) 打印(df_勾选) 用于计算间隙百分比的代码 #Calculating Gap Percentage df['Gap %'] = (df['Open'].sub(df['Close'].shift()).div(df['

我想使用一个数据帧中的一些日常数据作为限定符,在另一个数据帧中运行一些代码。两个数据帧都包含['Date'、'Time'、'Ticker'、'Open'、'High'、'Low'、'Close']。一个数据帧只有每日信息,另一个包含5分钟的相同字段,下面是一些示例

打印(df)

打印(df_勾选)

用于计算间隙百分比的代码

#Calculating Gap Percentage
df['Gap %'] = (df['Open'].sub(df['Close'].shift()).div(df['Close'] - 
1).fillna(0))*100
我有代码让df从Close-Open查找百分比变化,并希望使用此信息作为限定符,在df_勾号上运行一些代码

例如,如果df['Gap%]>.02,那么我希望在df_勾选中使用该日期,并忽略(或删除)其余信息

#drop rows not meeting certain percentage
df.drop(df[df['Gap %'] < .2].index, inplace=True)
现在我想使用df['Date']在df_tick['Date']中查找匹配的日期。对于我已经编写的一些代码,我试图删除所有日期不相同的数据。但是收到了一个错误

#drop rows in df_tick not matching dates in df
df_tick.drop(df_tick[df_tick['Date'] != df['Date']].index, inplace=True)

ValueError: Can only compare identically-labeled Series objects

您可能能够重置两个数据帧的索引,并且不做您正在尝试做的事情,但我会尝试以下方法:

df_tick=df_tick[df_tick.Date.isin(df.Date.unique())]
#drop rows not meeting certain percentage
df.drop(df[df['Gap %'] < .2].index, inplace=True)
       Date     Time Ticker     Open    High      Low    Close   Gap     Gap %
2  01/04/18  3:00 PM     ES  2719.25  2729.0  2718.25  2724.00  6.75  0.247888
3  01/05/18  3:00 PM     ES  2732.25  2743.0  2726.50  2741.25  8.25  0.301067
9  01/15/18  3:00 PM     ES  2793.75  2796.0  2792.50  2794.50  7.25  0.259531
#drop rows in df_tick not matching dates in df
df_tick.drop(df_tick[df_tick['Date'] != df['Date']].index, inplace=True)

ValueError: Can only compare identically-labeled Series objects