I am creating a sample dataframe:
tp = pd.DataFrame({'source':['a','s','f'],
'target':['b','n','m'],
'count':[0,8,4]})
And creating a column 'col' based on condition of 'target' column >> same as source, if matching condition, else to a default, as below:
tp['col'] = tp.apply(lambda row:row['source'] if row['target'] in ['b','n'] else 'x')
But it's throwing me this error: KeyError: ('target', 'occurred at index count')
How can I make it work, without defining a function?