I have a dataframe with four string columns
col1 col2 col3 col4
A. A. A. B.
A. A. A. A.
A. A. B. B.
Would like the response like this.
col1 col2 col3 col4 Changed
A. A. A. B. B
A. A. A. A.
A. A. B. B. B
lst = col1,col2,col3,col4
def compare(**kwargs):
if all(col1 for i in my_list):
return col1
elif all(col2 for i in my_list):
return col2
elif all(col3 for i in (col3,col4):
return col3
elif col4 == col4 :
return col2
df['changed'] = df.apply(lambda x: compare(x), axis = 1)
Bit stuck in getting this right if anyone can help?
Changedcolumn?