Description
Minimal example
df = pd.DataFrame(np.random.rand(49),
index=pd.DatetimeIndex(start='2018-04-01',
end='2018-04-03',
freq='1h')
)
print(df.head())
print(df.resample('D', loffset=pd.Timedelta('12h')).mean())
print(df.resample('D', loffset=pd.Timedelta('12h')).ffill())
Problem description
DataFrame
and DataFrameGroupBy
both provide a resample
method, for resampling timeseries data. These methods have an optional argument, loffset
, which accepts a pandas Timedelta
instance and is used to adjust the output DataFrame
's index, once a suitable aggregation method has been used on the resulting DatetimeIndexResampler
or DatetimeIndexResamplerGroupby
object.
This works as expected for, for example, mean
, but fails in the cases of ffill
, bfill
and pad
. The resample is successful, but the loffset
argument is ignored.
Expected Output
0
2018-04-01 00:00:00 0.246580
2018-04-01 01:00:00 0.380124
2018-04-01 02:00:00 0.227830
2018-04-01 03:00:00 0.376657
2018-04-01 04:00:00 0.139719
0
2018-04-01 12:00:00 0.434068
2018-04-02 12:00:00 0.471917
2018-04-03 12:00:00 0.395527
0
2018-04-01 12:00:00 0.246580
2018-04-02 12:00:00 0.402313
2018-04-03 12:00:00 0.395527
Output of pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.4.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 61 Stepping 4, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.22.0
pytest: 3.0.7
pip: 9.0.3
setuptools: 39.0.1
Cython: 0.27.3
numpy: 1.14.2
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 6.3.1
sphinx: 1.7.2
patsy: 0.4.1
dateutil: 2.7.2
pytz: 2018.4
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.2
feather: None
matplotlib: 2.1.2
openpyxl: 2.4.7
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 3.7.3
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.1.9
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None