Strange problem.
I have a dtype == object dataframe column with string values and NaNs. Looks like this:
df
Response
0 Email
1 NaN
2 NaN
3 Call
4 Email
5 Email
I want to use fillna to fill the NaN values with the most frequently occurring value - which in this case is 'email'.
code looks like this:
import numpy as np
import pandas as pd
most_frequent_cat = str(df['Response']).mode())
df['Response_imputed'] = df['Response']
df['Response_imputed'].fillna(most_freq_cat, inplace = True)
The results look like this:
df Response
0 Email
1 0 Email\ndtype: object
2 0 Email\ndtype: object
3 Call
4 Email
5 Email
0 Email\ndtype: object
is different than Email
If I remove the str
there is no replacement of the original NaN
s
What am I doing wrong?