Hello,
and please take my apologize for asking this way. My stackoverflow
question [1] was closed for IMHO no good reason. The linked duplicates
do not help me.
The example code below gives me this error using Pandas 2.2.0
FutureWarning: Downcasting behavior in `replace` is deprecated
and will be removed in a future version. To retain the old behavior,
explicitly call `result.infer_objects(copy=False)`.
To opt-in to the future behavior, set
`pd.set_option('future.no_silent_downcasting', True)`
s = s.replace(replace_dict)
I found several postings about this future warning. But my problem is I
don't understand why it happens and I also don't know how to solve it.
#!/usr/bin/python3
from pandas import Series
s = Series(['foo', 'bar'])
replace_dict = {'foo': 2, 'bar': 4}
s = s.replace(replace_dict)
I am aware of other questions and answers [2] but I don't know how to
apply them to my own code. The reason might be that I do not understand
the cause of the error.
The linked answers using `astype()` before replacement. But again: I
don't know how this could solve my problem.
Thanks in advance
Christian
[1] -- <
https://stackoverflow.com/q/77995105/4865723>
[2] -- <
https://stackoverflow.com/q/77900971/4865723>