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