0

I am trying to merge two dataframes (call them DF1 & DF2) that basically look like the below. My goal is:

  • I want open/close/low/high to all come from DF1.
  • I want numEvents and Volume = DF1 + DF2.
  • In cases where DF2 has rows that don't exist in DF1, I want open/close/low/high to be NaN (so I can later backfill them), and numEvents and Volume to come from DF2 as is.

Any help is much appreciated!

enter image description here

keynesiancross
  • 3,441
  • 15
  • 47
  • 87
  • num_events and volume are present in both dfs? – crazyglasses Jun 05 '17 at 11:58
  • Please read [this](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) on how to ask good pandas questions and [this](https://meta.stackoverflow.com/a/285557/487339) on why posting images instead of text is disfavoured. – DSM Jun 05 '17 at 12:57

2 Answers2

0

use pd.merge:

it's outer join since you want data from both dfs.

pd.merge([A,B],how='outer', on=<mutual_key>)

Dimgold
  • 2,748
  • 5
  • 26
  • 49
0

Use the left_on and right_on attributes of pd.merge(). You choose the fields that you want to merge.

DF1.merge(DF2, how='outer', right_on=<keys>...)
mx0
  • 6,445
  • 12
  • 49
  • 54