I have a dataframe as
import pandas as pd ndf = pd.DataFrame({'a':[False, False,True,True,False], 'b':[False, False,False,False, True]}) ndf_s = sqlContext.createDataFrame(ndf) I would like to get a new column named as "action". This could contain two values, if the ndf['a'] is True the "action" has value as "I am a", if ndf['b'] is True the "action" has value as "I am b". Otherwise get value None. In case both column are true, then return value as "I am a and b".In other word I would like to get a DataFrame as:
ndf_result = sqlContext.createDataFrame(pd.DataFrame({'a':[False, False,True,True,False], 'b':[False, False,False,False, True], 'action':[None, None, 'I am a', 'I am a', 'I am b']}))