ValueError: Series.replace cannot use dict-like to_replace and non-None value

Viewed 5112

When I update my pandas package today, what is working code suddenly got an error.

dfnc1['Age']=dfnc1['Age'].replace(dfn1['Age'].loc[(dfn1['Age']>=0) & (dfn1['Age']<=16)], '0-16')

I'm using this code to get Age columns which has range 0-16 into a new string category called '0-16'

But I got this error today

ValueError: Series.replace cannot use dict-like to_replace and non-None value

There is no null values

dfnc1['Age'].isnull().any()
False

The figure is also fine. Why I got this problem? How could I fix this?

dfnc1['Age'][:5]
0    22.0
1    38.0
2    26.0
3    35.0
4    35.0
Name: Age, dtype: float64
0 Answers
Related