Working with a Pandas DataFrame, df, and a function as follows
def code(x):
for item in x:
if x in [21,32]:
return'Cat A'
elif x in [22,34]:
return"Cat B"
else:
print ('sorry')
I have a DataFrame, df, which has one Column ('Ref') containing numbers
df =
**Document No** **Date**. **Ref**
2018-0212 2019-03-28 71
2018-0212R1 2019-03-28 71
2019-0004 2019-01-11 34
2019-0005 2019-01-14 25
I wish to iterate over that Column 'Ref' with the function above and return the result in a new Column appended to the df (i.e. a Column which would contain 'CAT A',or 'CAT B, or 'Sorry"
I have tried
df.apply.code(df['Ref'])
without success. Any thoughts? thanks