I have the following pandas dataframe:
In:
df = pd.DataFrame({'Fruits':['this should be a pinneapple',
'this should be an apple',
'this should be a tomato', 'this should 3 grapes',
'this should be an orange',
'this should be an 01',
'this should be an 02']})
df
Out:
Fruits
0 this should be a pinneapple
1 this should be an apple
2 this should be a tomato
3 this should 3 grapes
4 this should be an orange
5 this should be an 01
6 this should be an 02
I would like to replace all the fruits with an id (e.g. 01 to nn). For this I tried with pandas replace function:
df['Fruits'] = df['Fruits'].replace(['pinneapple', 'apple', 'tomato', 'grapes', 'orange'],\
['01', '02', '03', '04', '05'])
However, when I do the above assignment nothing is done to the column I am interested to tweak. Thus, how can I replace each word for a predefined number?.