Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
edited tags; edited tags
Link
EdChum
  • 396.6k
  • 204
  • 836
  • 583

I have two dataframes. df1 and df2. I would like to get whatever values are common from df1 and df2 and the dt value of df2 must be greater than df1's dt value In this case, the expected value is fee

df1 = pd.DataFrame([['2015-01-01 06:00','foo'], ['2015-01-01 07:00','fee'], ['2015-01-01 08:00','fum']],  columns=['dt', 'value']) df1.dt=pd.to_datetime(df1.dt) df2=pd.DataFrame([['2015-01-01 06:10','zoo'], ['2015-01-01 07:10','fee'],['2015-01-01 08:10','feu'], ['2015-01-01 09:10','boo']], columns=['dt', 'value']) df2.dt=pd.to_datetime(df2.dt) 

I have two dataframes. df1 and df2. I would like to get whatever values are common from df1 and df2 and the dt value of df2 must be greater than df1's dt value In this case, the expected value is fee

df1 = pd.DataFrame([['2015-01-01 06:00','foo'],['2015-01-01 07:00','fee'],['2015-01-01 08:00','fum']], columns=['dt', 'value']) df1.dt=pd.to_datetime(df1.dt) df2=pd.DataFrame([['2015-01-01 06:10','zoo'],['2015-01-01 07:10','fee'],['2015-01-01 08:10','feu'],['2015-01-01 09:10','boo']], columns=['dt', 'value']) df2.dt=pd.to_datetime(df2.dt) 

I have two dataframes. df1 and df2. I would like to get whatever values are common from df1 and df2 and the dt value of df2 must be greater than df1's dt value In this case, the expected value is fee

df1 = pd.DataFrame([['2015-01-01 06:00','foo'], ['2015-01-01 07:00','fee'], ['2015-01-01 08:00','fum']],  columns=['dt', 'value']) df1.dt=pd.to_datetime(df1.dt) df2=pd.DataFrame([['2015-01-01 06:10','zoo'], ['2015-01-01 07:10','fee'],['2015-01-01 08:10','feu'], ['2015-01-01 09:10','boo']], columns=['dt', 'value']) df2.dt=pd.to_datetime(df2.dt) 
Source Link
NinjaGaiden
  • 3.1k
  • 7
  • 34
  • 50

pandas compare two dataframes with criteria

I have two dataframes. df1 and df2. I would like to get whatever values are common from df1 and df2 and the dt value of df2 must be greater than df1's dt value In this case, the expected value is fee

df1 = pd.DataFrame([['2015-01-01 06:00','foo'],['2015-01-01 07:00','fee'],['2015-01-01 08:00','fum']], columns=['dt', 'value']) df1.dt=pd.to_datetime(df1.dt) df2=pd.DataFrame([['2015-01-01 06:10','zoo'],['2015-01-01 07:10','fee'],['2015-01-01 08:10','feu'],['2015-01-01 09:10','boo']], columns=['dt', 'value']) df2.dt=pd.to_datetime(df2.dt)