How do I return a list based on multiple filters from multiple dataframes? I have three dataframes:
df1
Ticker Company Name COMBOACCRUAL
0 ABC ABC Co. 0.9
1 DEF DEF Co. 0.99
2 GHI GHI Co. 0.5
df2
Ticker Company Name PMAN
0 ABC ABC Co. 0.7
1 DEF DEF Co. 0.3
2 GHI GHI Co. 0.55
df3
Ticker Company Name PFD
0 ABC ABC Co. 0.25
1 DEF DEF Co. 0.35
2 GHI GHI Co. 0.9
and I want to apply filters COMBOACCRUAL<0.95
, PMAN<0.95
and PFD<0.95
on the dataframes df1
df2
and df3
respectively so I could work further on the culled data.
The expected result should look like this:
df4
Ticker Company Name COMBOACCRUAL PMAN PFD
0 ABC ABC Co. 0.9 0.7 0.25
2 GHI GHI Co. 0.5 0.55 0.9
CodePudding user response:
Merge the three df together first and apply your filter?
columns = ['Ticker', 'Company', 'Name']
df4 = df1.merge(df2, on=columns).merge(df3, on=columns)
df4 = df4[(df4['COMBOACCRUAL'] < 0.95) & (df4['PMAN'] < 0.95) & (df4['PFD'] < 0.95)]