Darekdari / Python Pandas

FutureWarning in Pandas: fillna(method) Is Deprecated

Seeing “Series.fillna with ‘method’ is deprecated”? Here is what it means and how to fix it with ffill() and bfill(), with copy-ready examples.

Introduction

Introduction

If you clean data with pandas, you have probably written df.fillna(method='ffill') a hundred times. Recent pandas versions now print a FutureWarning every time you do. Your code still runs, but the warning is telling you the old style is on its way out.

The fix is small and mechanical: use .ffill() or .bfill() instead. This guide shows exactly how, including the groupby, limit, resample, and interpolate cases people trip over.

Quick answer: replace df.fillna(method='ffill') with df.ffill(), and df.fillna(method='bfill') with df.bfill(). Filling with a value, like df.fillna(0), is not deprecated.

The warning

What the FutureWarning Looks Like

Running code like this on a recent pandas version triggers the warning:

trigger_warning.py
import pandas as pd
import numpy as np

s = pd.Series([1.0, np.nan, 3.0])

result = s.fillna(method='ffill')

You will see a message similar to this:

output.txt
FutureWarning: Series.fillna with 'method' is deprecated and will raise
in a future version. Use obj.ffill() or obj.bfill() instead.

The exact wording can vary slightly by pandas version, and you may see DataFrame.fillna instead of Series.fillna. The meaning is the same.

The deprecation of the method and limit keywords on fillna was introduced in pandas 2.1.0.
Background

Why Was fillna(method=) Deprecated?

The pandas team wanted each method to do one clear job. fillna was doing two different things depending on its arguments: filling with a value, or propagating existing values forward or backward. Those already had dedicated methods, ffill and bfill, so the overlapping method keyword was deprecated.

fillna(value)Fill missing values with a value you choose, such as 0 or a column mean.
ffill()Forward fill: carry the last valid observation forward.
bfill()Backward fill: use the next valid observation to fill the gap.

Don’t ignore it: a FutureWarning means the old behavior will eventually be removed. Newer pandas major versions have already removed some deprecated fill APIs (for example GroupBy.fillna and Resampler.fillna), so code that only warns today may fail after an upgrade.

The fix

Replace fillna(method=) with ffill() and bfill()

Forward fill

ffill_fix.py
import pandas as pd
import numpy as np

s = pd.Series([1.0, np.nan, np.nan, 4.0])

# Old (deprecated)
# s = s.fillna(method='ffill')

# New
s = s.ffill()

print(s)

The result is 1.0, 1.0, 1.0, 4.0: each missing value takes the last valid value before it.

Backward fill

bfill_fix.py
s = pd.Series([np.nan, np.nan, 3.0, 4.0])

# Old (deprecated)
# s = s.fillna(method='bfill')

# New
s = s.bfill()

print(s)

The result is 3.0, 3.0, 3.0, 4.0: each missing value takes the next valid value after it.

On a whole DataFrame or a single column

dataframe_fix.py
df = pd.DataFrame({
    'price': [10, np.nan, np.nan, 13, np.nan],
    'qty':   [1, 2, np.nan, 4, 5]
})

# Whole DataFrame
df_filled = df.ffill()

# One column
df['price'] = df['price'].ffill()

# Different strategy per column
df['price'] = df['price'].ffill()
df['qty'] = df['qty'].bfill()

Fill the leftover gaps

Forward fill cannot fill missing values at the very start, since there is nothing before them. Chain a value fill to cover those:

ffill_then_value.py
df['price'] = df['price'].ffill().fillna(0)
Value fills are still fine: df['col'].fillna(0) and df.fillna({'a': 0, 'b': 'unknown'}) do not trigger this warning.
More cases

Limit, GroupBy, Resample, and Interpolate

The limit argument

If you used fillna(method='ffill', limit=2), pass limit to the new methods:

limit_fix.py
# Old (deprecated)
# df = df.fillna(method='ffill', limit=2)

# New
df = df.ffill(limit=2)

Filling across columns (axis)

axis_fix.py
# Old (deprecated)
# df = df.fillna(method='ffill', axis=1)

# New
df = df.ffill(axis=1)

Filling within groups

A common pattern is filling gaps separately for each group. Use groupby with ffill or bfill:

groupby_fix.py
df = pd.DataFrame({
    'store': ['A', 'A', 'A', 'B', 'B', 'B'],
    'sales': [100, np.nan, 120, np.nan, 80, np.nan]
})

# Old (deprecated)
# df['sales'] = df.groupby('store')['sales'].fillna(method='ffill')

# New
df['sales'] = df.groupby('store')['sales'].ffill()

print(df)

Filling within each group keeps one store’s values from leaking into another. Note that GroupBy.fillna was itself deprecated in pandas 2.2 and has been removed in pandas 3.0, so use groupby(...).ffill() or .bfill().

Resampling

resample_fix.py
idx = pd.date_range('2026-01-01', periods=3, freq='h')
s = pd.Series([1.0, np.nan, 3.0], index=idx)

# Old (deprecated)
# s.resample('30min').fillna('pad')

# New
s.resample('30min').ffill()
s.resample('30min').bfill()
s.resample('30min').nearest()

Resampler.fillna was deprecated and removed in pandas 3.0. Use ffill(), bfill(), or nearest() on the resampler.

Interpolate with pad or backfill

interpolate_fix.py
# Old (deprecated)
# s = s.interpolate(method='pad')

# New
s = s.ffill()

The values 'pad', 'ffill', 'bfill', and 'backfill' passed to interpolate are deprecated too. Call ffill() or bfill() directly.

Cheat sheet

Old Code vs New Code

Keep this table handy while you update your code.

Old (deprecated)New
df.fillna(method='ffill')df.ffill()
df.fillna(method='pad')df.ffill()
df.fillna(method='bfill')df.bfill()
df.fillna(method='backfill')df.bfill()
df.fillna(method='ffill', limit=2)df.ffill(limit=2)
df.fillna(method='ffill', axis=1)df.ffill(axis=1)
df.groupby('g')['x'].fillna(method='ffill')df.groupby('g')['x'].ffill()
s.resample('30min').fillna('pad')s.resample('30min').ffill()
s.interpolate(method='pad')s.ffill()
df.fillna(0)No change needed
Cleanup

How to Find Every Occurrence in Your Project

Search your code

terminal
grep -rn "fillna(method" .
grep -rn "method=.ffill" .
grep -rn "method=.bfill" .

Turn warnings into errors to catch them all

Run your script or tests so a FutureWarning becomes an error. You will get a traceback pointing at the exact line:

terminal
python -W error::FutureWarning your_script.py

pytest -W error::FutureWarning

Check your pandas version

check_version.py
import pandas as pd

print(pd.__version__)

Avoid just hiding the warning. Silencing it with warnings.filterwarnings('ignore') removes the message, not the problem. Replace the deprecated calls instead so your code keeps working when you upgrade pandas.

A related but separate warning mentions “downcasting object dtype arrays” after fillna. It has a different cause, so read its message and the pandas release notes for the recommended change.
pandas fillna deprecatedpandas ffillpandas bfillFutureWarning pandasfix pandas warning

Learn more

More info about us

FAQ

Frequently Asked Questions (FAQs)

Quick answers about the pandas fillna deprecation.

Q: What does the FutureWarning for fillna method mean?+

A: It means the method keyword of fillna (for example method='ffill') is deprecated and will be removed in a future version. Use obj.ffill() or obj.bfill() instead.

Q: What replaces fillna(method=’ffill’)?+

A: Use .ffill(). For example, df['col'].ffill() forward-fills missing values with the last valid observation.

Q: What replaces fillna(method=’bfill’)?+

A: Use .bfill(), which fills missing values with the next valid observation.

Q: Is fillna itself deprecated?+

A: No. Filling with a value, such as df['col'].fillna(0) or df.fillna({'a': 0}), is still supported. Only the method keyword is deprecated.

Q: What about the limit argument?+

A: Pass limit to ffill or bfill, for example df.ffill(limit=2). The limit keyword on fillna is deprecated when used with method.

Q: How do I forward-fill within groups?+

A: Use df.groupby('store')['sales'].ffill(). GroupBy.fillna was deprecated in pandas 2.2 and removed in pandas 3.0.

Q: Which pandas version introduced this warning?+

A: The deprecation of the method and limit keywords on fillna was added in pandas 2.1.0.

Q: Should I just hide the warning?+

A: No. Hiding it only delays the problem. Replace fillna(method=...) with ffill() or bfill() so your code keeps working in newer pandas versions.

Still stuck? Shoot us a message and our crew will steer you in the right direction. Happy coding with pandas! 🐼✨

pandas fillna deprecated
Conclusion

Conclusion

The pandas FutureWarning about fillna(method=...) is easy to fix. Swap fillna(method='ffill') for ffill(), swap fillna(method='bfill') for bfill(), move limit and axis onto the new methods, and use groupby(...).ffill() for grouped data.

Do the cleanup now with the search and -W error::FutureWarning tips above, and your code will stay clean across pandas upgrades. Happy coding! 🚀

Scroll to Top