trying to apply this logic to the following DF
I have a df as follows
import pandas as pd
import numpy as pd
df = pd.read_csv('subjects.csv')
Subjects
Media
information Media
Digital Media
I then try to map my subjects to a dict to output a validated corrected_subject
d = {'Media' : 'Film & Media',
'Information' : 'ICT',
'Digital' : 'ICT'}
df['subject_corrected'] = df['subjects'](lambda x: ', '.join([d[i] for i in d if i in x]))
Subjects subject_corrected
Media Film & Media
information Media Film & Media, ICT
Digital Media Film & Media, ICT
now using this loops through my DF giving me all matches where I want it to find the closest match and exit the loop. so Digital Media would be ICT and not Media
I have tried the following but it hasn't really boded well for me! for
for k,v in d.items():
if k in df['subjects']:
df['subject_corrected'] = d.values():
Subjects subject_corrected
Media Film & Media
information Media ICT
Digital Media ICT
I've had a look at quite a few similar posts but couldn't work this one out.
am I going around this the wrong way, shall I pass this into two lists/arrays and use an if statement to loop through any matches? also how is a dict different from a 2D Array.
Any help is appreciated.