Pandas time series Resample

Source: Internet
Author: User


The difference between resample and GroupBy:
Resample: Resampling within a given time unit
GroupBy: Statistics on a given data entry

Function Prototypes:
Dataframe.resample (rule, How=none, axis=0, Fill_method=none, Closed=none, Label=none, convention= ' start ', Kind=None, Loffset=none, Limit=none, base=0)
Where the parameters are deprecated.


Let's start practicing.

Import NumPy as NP import Pandas as PD


Start by creating a series with 9 one minute timestamps.

index = Pd.date_range ('1/1/2000', periods=9, freq='T'  = PD. Series (Range (9), Index=index)


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

Series.resample ('3T'). SUM ()


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

Series.resample ('3T', label='right'). SUM ()



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

Series.resample ('3T', label='right', closed='  Right'). SUM ()



Upsample the series into the second bins.

Series.resample ('30S'). Asfreq ()


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

Series.resample ('30S'). Pad ()


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

Series.resample ('30S'). Bfill ()


Pass a custom function via apply

def Custom_resampler (array_like):     return np.sum (array_like) +5series.resample ('3T'). Apply (Custom_ Resampler)



Attached: Common time frequency
Year A
M Month
W Week
D Day
H Hour
T minute
S Second


Pandas time series Resample

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.