I have this dataframe:
df = pd.DataFrame( {'an2': {0: 'f', 1: 'i', 2: '', 3: '', 4: 'f', 5: 'c,f,i,g', 6: 'c,d,e,g'}} )
which yields to:
an2
0 f
1 i
2
3
4 f
5 c,f,i,g
6 c,d,e,g
I would like to create new column df['an3'] by renaming df['an2'] according to the following dictionary:
dic = {'a': 'john',
'b': 'paul',
'c': 'mike',
'd': 'elephant',
'e': 'water',
'f': 'bread',
'g': 'julie',
'h': 'anna',
'i': 'mauricio',
'j': 'claudia'}
Therefore desired output is:
an2 an3
0 f bread
1 i mauricio
2
3
4 f bread
5 c,f,i,g mike,bread,mauricio,claudia
6 c,d,e,g mike,elephant,water,claudia
I tried using dictionary above with the following code
df['an3'] = df['fan2'].replace(dic)
unfortunatley it only work for those cells where one single entry was found on df['an2']