Comparing and Count Values from 2 (or More) Different Pandas Dataframes Based on Certain Conditions
To See The Companies That Are In Both Data Frames
1st part
combined_dataframe1=df1[df2['company'].isin(df1['company'])]
combined_dataframe1['company']
2nd part
To see the company that satisfies your conditions
combined_dataframe2=df2[df2['company'].isin(df1['company'])]
joined_dataframe=pd.merge(combined_dataframe1,combined_dataframe2, on='company',how='outer')
As per your condition
final_dataframe=joined_dataframe[joined_dataframe.columns][joined_dataframe['po_x']=='n0'}[joined_dataframe['act_call_yes']=='yes'][joined_dataframe['act_visit_y']=='yes']
print(final_dataframe)
Assuming that I have monthly datasets showing like these:
df1




company
date
act_call
act_visit
po




A
2022-10-01
Yes
No
No


B
2022-10-01
Yes
No
Yes


C
2022-10-01
No
No
No


B
2022-10-02
No
Yes
No


A
2022-10-02
No
Yes
Yes




df2




company
date
act_call
act_visit
po




D
2022-11-01
Yes
No
No


B
2022-11-01
Yes
No
Yes


C
2022-11-01
Yes
Yes
No


D
2022-11-02
No
Yes
No


A
2022-11-02
No
Yes
Yes




I want to compare the two dataframes and count several conditions:

the number of company that exists in both dataframes.

the number of company that exists in both dataframes that has at least one act_call as 'Yes' and act_visit as 'Yes' in df2, but has po as 'No' in df1.


For the 1st condition, I've tried using pandas.Dataframe.sum() and pandas.Dataframe.count_values() but they didn't give the results that I want.
For the 2nd condition, I tried using this code:
(((df1[['act_calling', 'act_visit']].eq('yes'))&(df2['po'].eq('no'))).groupby(df2['company_name']).any().all(axis = 1).sum())
but, I'm not sure that the code above will only count the company that exists in both dataframes.
The expected output is this:

3, (A, B, C)

1, (C)


I'm open to any suggestions. Thank u in advance!