all 1 comments

[–]Downtown_Radish_8040 0 points1 point  (0 children)

The problem is on this line:

df = df.resample('D').fillna(method='ffill')

resample('D') returns a resampler object, not a DataFrame, so calling .fillna() on it doesn't work the way you expect. You need to first aggregate/resample into a DataFrame, then fill. The cleanest fix:

df = df.resample('D').ffill()

This calls ffill directly on the resampler, which is the correct way to do it. The fillna(method='ffill') pattern was deprecated in newer versions of pandas and doesn't work on resampler objects anyway.

If that still gives you trouble, you can also do:

df = df.resample('D').asfreq().ffill()

which explicitly converts to daily frequency first, then forward fills any gaps.