Python Pandas v0.18+:有没有办法在不填充 NA 的情况下对数据帧进行重采样?

Python Pandas v0.18+: is there a way to resample a dataframe without filling NAs?

我想知道是否有一种方法可以对 DataFrame 重新采样,而不必立即决定如何填充 NA。

我尝试了以下方法但收到了未来警告:

FutureWarning: .resample() is now a deferred operation use .resample(...).mean() instead of .resample(...)

代码:

import pandas as pd
dates = pd.date_range('2015-01-01', '2016-01-01', freq='BM')
dummy = [i for i in range(len(dates))]
df = pd.DataFrame({'A': dummy})
df.index = dates
df.resample('B')

有没有更好的方法来做到这一点,不显示警告?

谢谢。

使用Resampler.asfreq:

print (df.resample('B').asfreq())
               A
2015-01-30   0.0
2015-02-02   NaN
2015-02-03   NaN
2015-02-04   NaN
2015-02-05   NaN
2015-02-06   NaN
2015-02-09   NaN
2015-02-10   NaN
2015-02-11   NaN
2015-02-12   NaN
2015-02-13   NaN
2015-02-16   NaN
2015-02-17   NaN
2015-02-18   NaN
2015-02-19   NaN
2015-02-20   NaN
2015-02-23   NaN
2015-02-24   NaN
2015-02-25   NaN
2015-02-26   NaN
2015-02-27   1.0
2015-03-02   NaN
2015-03-03   NaN
2015-03-04   NaN
...
...