I have a column X in my dataset which consists following data
1,
2,
4,
5more,
3,
2
So when I used
dataset['X'].map({
"5more" : 5
})
It is converting all values to NaN
.
How to convert these dataset to numerical without NaN/Infinity?
I have a column X in my dataset which consists following data
1,
2,
4,
5more,
3,
2
So when I used
dataset['X'].map({
"5more" : 5
})
It is converting all values to NaN
.
How to convert these dataset to numerical without NaN/Infinity?
With map all keys that are not in dictionary are replaced with NaN. From pandas documentation on map
When arg is a dictionary, values in Series that are not in the dictionary (as keys) are converted to NaN.
You can try using replace
:
dataset['X'].replace("5more" : 5})
You can also add inplace=True
to replace inplace:
dataset['X'].replace("5more" : 5}, inplace=True)