Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pandas 2.1.0 warning ''The 'method' keyword in Series.replace is deprecated and will be removed in a future version''

I have a pandas line of code that gives me a future deprecation warning as stated in the title and I can’t find in the pandas documentation how to modify it in order to remove the warning. The line of code is the following:

df['temp_open']=df['temp_open'].replace('',method='ffill')

Any help would be greatly appreciated.

I tried to fill blanks and it works, but I would like to get rid of the warning.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can do this instead :

df["temp_open"] = df["temp_open"].replace("", None).ffill()

And if you want to keep the nulls (if any) untouched, you can use :

df["temp_open"] = (
    df["temp_open"].replace("", None).ffill().where(df["temp_open"].notnull())
)

Output :

print(df)

  temp_open
0         A
1         A
2       NaN
3         B
4         C
5         C

Used input :

df = pd.DataFrame({"temp_open": ["A", "", None, "B", "C", ""]})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading