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.
>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", ""]})