2

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
AlexWithYou
  • 399
  • 1
  • 4
  • 14
  • hi @jezrael The problem is still the same – AlexWithYou Dec 02 '20 at 08:37
  • @jezrael. No, Just replace the values. my previous pandas package work fine, but this new version got this value error. I don't know why, did you try in your IDE? – AlexWithYou Dec 02 '20 at 08:41
  • Or maybe need change `dfn1['Age'].loc[(dfn1['Age']>=0) & (dfn1['Age']<=16)]` to `dfn1['Age'].loc[(dfn1['Age']>=0) & (dfn1['Age']<=16)].tolist()` or `dfn1.loc[(dfn1['Age']>=0) & (dfn1['Age']<=16), 'Age'].tolist()` – jezrael Dec 02 '20 at 08:41
  • One important thing - why is not tested columns in `dfnc1` like `dfnc1.loc[(dfnc1['Age']>=0) & (dfnc1['Age']<=16), 'new']= '0-16'? Is necessary second DataFrame `dfn1` ? – jezrael Dec 02 '20 at 08:45
  • The .tolist() method works, I am still intested in it's changes though. I changed 10 lines of code when they are working fine before this updating. – AlexWithYou Dec 02 '20 at 08:46
  • ya, reason should be some newer version of pandas is more strict, so cannot pass Series – jezrael Dec 02 '20 at 08:47
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/225395/discussion-between-alexwithyou-and-jezrael). – AlexWithYou Dec 02 '20 at 08:48

0 Answers0