I have two dataframes made with Pandas in python:
df1
id business state inBusiness
1 painter AL no
2 insurance AL no
3 lawyer OH no
4 dentist NY yes
...........
df2
id business state
1 painter NY
2 painter AL
3 builder TX
4 painter AL
......
Basically, I want to set the 'inBusiness' value in df1 to 'yes' if an instance of the exact same business/location combo exists in df2.
So for example, if painter/AL exists in df2, than all instances of painter/AL in df1 have their 'inBusiness' value set to yes.
The best I can come up with right now is this:
for index, row in df2.iterrows():
df1[ (df1.business==str(row['business'])) & (df1.state==str(row['state']))]['inBusiness'] = 'Yes'
but the first dataframe can potentially have hundreds of thousands of rows to loop through for each row in the second dataframe so this method is not very reliable. Is there a nice one-liner I can use here that would also be quick?