This is also a documentation error, as the docs say the default axis is axis = 0
import pandas as pd
from pandas.util.testing import makePanel
#
# Demo A: We want to fill along axis 0
#
p = makePanel().transpose(1,0,2)
p.iloc[10:20,0,0] = np.nan
# Demonstrate we have a gap
p.iloc[:,0,0].plot()
# Demonstrate that nothing seems to fill the gap
p.fillna(method='ffill').iloc[:,0,0].plot()
p.fillna(method='ffill', axis=0).iloc[:,0,0].plot()
p.fillna(method='ffill', axis=1).iloc[:,0,0].plot()
p.fillna(method='ffill', axis=2).iloc[:,0,0].plot()
# At least one of the above should be the same as:
p.apply(lambda series: series.fillna(method='ffill'), axis=0).iloc[:,0,0].plot()
#
# Demo B: We want to fill along axis 1
#
p = makePanel()
p.iloc[0, 10:20,0] = np.nan
# Demonstrate we have a gap
p.iloc[0,:,0].plot()
# Demonstrate the gap is filled regardless of the axis
p.fillna(method='ffill').iloc[0,:,0].plot()
p.fillna(method='ffill', axis=0).iloc[0,:,0].plot()
p.fillna(method='ffill', axis=1).iloc[0,:,0].plot()
p.fillna(method='ffill', axis=2).iloc[0,:,0].plot()
Comment From: jreback
looks like a bug. Panel.fillna not tested very well. I can see that the axis does not appear to be passed thru correctly.
pull-request welcome. Would like to have comprehensive tests for this (don't use plot though), construct a test panel and its expected output and check for equality.
Comment From: staple
Hi I started working on this yesterday as well, looks like there was a collision. @stahlous, feel free to pull in anything from my patch (including test cases). I'm going to close my PR now in deference to @stahlous who submitted the first PR. https://github.com/pydata/pandas/pull/8401
Comment From: thusson
Note too that the limit parameter is also ignored. Change the last few lines of the above example to:
p.fillna(method='ffill', axis=0, limit=5).iloc[0,:,0].plot() p.fillna(method='ffill', axis=1, limit=5).iloc[0,:,0].plot() p.fillna(method='ffill', axis=2, limit=5).iloc[0,:,0].plot()
And you can see it fills beyond 5 items.
Comment From: jreback
closing as Panel deprecated