Reputation: 11
The data type of the column is object. but, i still map it to string using astype(str)
. even used temp['Injury Severity'].str.strip()
to remove spaces from column values.
I want to replace all "Fatal(0)",Fatal(1)"... with only "Fatal". so i used.temp['Injury Severity'] = temp['Injury Severity'].replace('Fatal(0)','Fatal',inplace = True)
.
But did not work. i also tried temp.loc[temp['Injury Severity'] == 'Fatal(0)','Injury Severity'] = temp['Injury Severity'].replace('Fatal(0)','Fatal',inplace = True)
In addition is tried str.replace
but did not work out.lastly also used regex = True
but no changes was observed.It still remains the same.
Upvotes: 0
Views: 53
Reputation: 11
I think it is solved. It seems that the values were having leading and trailing spaces in the name of values.Thanks alot for the help everyone !!
Upvotes: 1
Reputation: 323
Try This,
temp['Injury Severity'].replace('Fatal(0)','Fatal',inplace = True)
No need to assign it again.
Upvotes: 0