I'm trying to map my values that i want to change. When i apply 'map' like this >> df[column].map(dictionary), the values that are not in the dictionary convert to NaN. I think the reason is that there are no matched values in the series, right? If so, nothing should be applied instead converting to NaN? How can i solve this problem using df.map() instead of df.replace()?
df1 = pd.Series(['a','b','c','d'])
df
0 a
1 b
2 c
3 d
dtype: object
mapping = {'a' : 0, 'b' : 1, 'c' : 2}
df1.map(mapping)
0 0.0
1 1.0
2 2.0
3 NaN
dtype: float64
or
df1 = pd.Series(['a','b','c','d'])
df
0 a
1 b
2 c
3 d
dtype: object
mapping = {'k' : 0, 'e' : 1, 'f' : 2}
df1.map(mapping)
0 NaN
1 NaN
2 NaN
3 NaN
dtype: float64