I have 1 large dataframe, and 2 smaller dataframes in which I would like to append/match based on certain criteria.
Data
df1 (large dataframe)
id Date pp pos
aa q122 200 10
aa q222 200 10
bb q322 500 5
bb q422 500 5
cc q122 100 2
cc q222 100 2
df2
name date1 count1 pp1
aa q122 3 30
aa q222 5 10
df3
ex date2 count2 pp2
cc q122 3 30
cc q222 5 10
Desired
id Date pp pos name date1 count1 pwr1 ex date2 count2 pwr2
aa q122 200 10 aa q122 3 30 NaN NaN 0 0
aa q222 200 10 aa q222 5 10 NaN NaN 0 0
bb q322 500 5 NaN NaN 0 0 NaN NaN 0 0
bb q422 500 5 NaN NaN 0 0 NaN NaN 0 0
cc q122 100 2 NaN NaN 0 0 cc q122 3 30
cc q222 100 2 NaN NaN 0 0 cc q222 5 10
Logic: I am matching the individual dataframes based on whether the 'name' and 'ex' values match the 'id' value as well as the 'date'
Doing
df1['id'] = df1['name'].combine_first(df1['ex'])
out = df2.merge(df1, on=['id', 'date'], how='outer')
But getting a little lost on how to incorporate the 3rd dataframe Any suggestion is appreciated