Skip to content

Resampling Time Series Data with Pandas

Daniel Goldfarb edited this page Jan 28, 2020 · 13 revisions

The following is from Resampling Time Series Data with Pandas

Resampling options

  • pandas comes with many in-built options for resampling, and you can even define your own methods.
  • In terms of date ranges, the following is a table for common time period options when resampling a time series:
Alias Description
B Business day
D Calendar day
W Weekly
M Month end
Q Quarter end
A Year end
BA Business year end
AS Year start
H Hourly frequency
T, min Minutely frequency
S Secondly frequency
L, ms Millisecond frequency
U, us Microsecond frequency
N, ns Nanosecond frequency

These are some of the common methods you might use for resampling:

Method Description
bfill Backward fill
count Count of values
ffill Forward fill
first First valid data value
last Last valid data value
max Maximum data value
mean Mean of values in time range
median Median of values in time range
min Minimum data value
nunique Number of unique values
ohlc Opening value, highest value, lowest value, closing value
pad Same as forward fill
std Standard deviation of values
sum Sum of values
var Variance of values