I currently have a dataframe like this
colA colB colC colD
1 1a Yes Yes
1 1b Yes Yes
2 2a Yes Yes
2 2b Yes Yes
2 2c Yes Yes
3 3a Yes Yes
4 4a Yes Yes
Say I have a dictionary like this
filterDict = {
"1" : ["1a","1b"]
"2" : ["2a","2b"]
}
I want it so that if in colA a value exists as a key, check if colB in that same row exists in the value list of the dict for that key so that the resulting dataframe would look like this
colA colB colC colD
1 1a No No
1 1b No No
2 2a No No
2 2b No No
2 2c Yes Yes
3 3a Yes Yes
4 4a Yes Yes
I am relatively new to pandas and am unsure how to do this. What I previously had was something hardcoded like this
mask = ((df["colA"] == "1") & (df["colB"].isin(["1a","1b"])) |
((df["colB"] == "2") & (df["colB"].isin(["2a","2b"]))
df.loc[mask,["colC","colD"]] = ["No","No"]
But I would like this to be dynamic so that it could be put in the dict format