I have this df:
import pandas as pd
df1 = pd.DataFrame({
'Type': ['red', 'blue', 'red', 'red', 'blue'],
'V1': ['No', 'No', 'No', 'Yes', 'No'],
'V2': ['Yes', 'Yes', 'No', 'Yes', 'No'],
'V3': ['Yes', 'No', 'No', 'Yes', 'No'],
'V4': ['No', 'No', 'No', 'Yes', 'Yes']
})
And I want a dataframe that looks like this:
Type V1 V2 V3 V4 V3_4
0 red No Yes Yes No Yes
1 blue No Yes No No No
2 red No No No No No
3 red Yes Yes Yes Yes Yes
4 blue No No No Yes Yes
So basically any "Yes" values from V3 are carried forward into a new column V3_4 as well as "Yes" values from V4 into column V3_4.
It looks like I can do this either with a ffill or build a python function with some logic. I would be fine with either method and am wondering what the most elegant is.