I have a master dataframe with two sets of values:
df1 = pd.DataFrame({'id1': [1, 1, 2, 2],
'dir1': [True, False, True, False],
'value1': [55, 40, 84, 31],
'id2': [3, 3, 4, 4],
'dir2': [True, False, False, True],
'value2': [60, 30, 7, 15]})
id1 dir1 value1 id2 dir2 value2
0 1 True 55 3 True 60
1 1 False 40 3 False 30
2 2 True 84 4 False 7
3 2 False 31 4 True 15
I then have an update dataframe that looks like this:
df2 = pd.DataFrame({'id': [1, 2, 3, 4],
'value': [21, 22, 23, 24]})
id value
0 1 21
1 2 22
2 3 23
3 4 24
I want to update df1 with the new values of df2 but only where dirX is True. Data should then look like this:
id1 dir1 value1 id2 dir2 value2
0 1 True *21 3 True *23
1 1 False 40 3 False 30
2 2 True *22 4 False 7
3 2 False 31 4 True *24
Any idea if something like this is even possible? I tried looking at .update but I could not get it to work. I'm fairly new to python and only coding at 23:00, so maybe I'm just not as sharp as I need to be.