天天看點

pandas 時間序列resample

resample與groupby的差別:

resample:在給定的時間機關内重取樣

groupby:對給定的資料條目進行統計

函數原型:

DataFrame.resample(rule, how=None, axis=0, fill_method=None, closed=None, label=None, convention='start', kind=None, loffset=None, limit=None, base=0)

其中,參數how已經廢棄了。

下面開始練習

Start by creating a series with 9 one minute timestamps.

Downsample the series into 3 minute bins and sum the values of the timestamps falling into a bin.

To include this value close the right side of the bin interval as illustrated in the example below this one.

Downsample the series into 3 minute bins as above, but close the right side of the bin interval.

Upsample the series into 30 second bins.

Upsample the series into 30 second bins and fill the NaN values using the pad method.

Upsample the series into 30 second bins and fill the NaN values using the bfill method.

Pass a custom function via apply

附:常見時間頻率

A year

M month

W week

D day

H hour

T minute

S second