I have this dataset:
training.head()
Out[115]:
GridID date Shift Accident
0 1 2010-10-08 Night 0
1 1 2011-02-16 Morning 0
2 1 2014-05-31 Night 0
3 1 2011-04-03 Afternoon 0
4 1 2013-02-20 Morning 0
I would like to replace in column Shift the words "Morning", "Afternoon" and "Night" with integers 1, 2 and 3, repectively.
I tried:
training['Shift'].str.replace('Morninig','1').astype(int)
But it gives me:
ValueError: invalid literal for int() with base 10: 'Night'

intusingastype(int)Nightin column. Column can have only onetypesoastype(int)convert all elements in column.