I am trying to create a simple data frame that imports a CSV file containing 3 columns ['Date','Amount','Description'] being banking transactions. and then applies a code. I have created a simple function to return the code.
def codelookup(string):
code_dict = {'GOLFBOX':'Golf Clubs','HARVEY NORMAN': 'TECH','AMAZON': 'TECH'}
for code in code_dict:
if code in string:
return str(code_dict[code])
break
else:
return 'Other'
df_data = pd.DataFrame({'Date': ['28/12/18','28/12/18','27/12/18'],
'Amount': [-307.99,-14,-43.86],
'Description': ['GOLFBOX OSBORNE PARK OSBORNE PARK','CLUBLINKS MANAGEMENT P COMO','WOOLWORTHS 4301 PERTH']})
df_data["Code"] = codelookup(df_data['Description'])
df_data
The result I am returned with the function is 'Other', in each of the 3 transactions. It's not correctly sending the 'Description' to the function as the function works with a simple call.
I'm a newbie so apologies for the description of my issue, be keen to see a cleaner way to do this lookup.
Regards JDLove