data = [{'a': 12, 'b': 2, 'c': 3, 'd': 'bat'},
{'a': 'NaN', 'b': 20, 'c': 30, 'd': 'ball'},
{'a': 4, 'b': 20, 'c': 30, 'd': 'pin'}]
df = pd.DataFrame(data)
I'm having a hard time figuring out how to replace the NaN values in column A with values in column b based on conditions set on columns c and d. For example, if I wanted to replace the NaN values in the a column with the values of column b (2 and 20, respectively) under circumstances where the value of c > 20 and 'd' = 'ball.
Could someone help me with this?
I've tried a number of solutions with df.loc and df.mask that have not worked.