Questions tagged [pandas-resample]

Relating to up- or down-sampling time series data in the Python package pandas, specifically the methods pandas.DataFrame.resample() and pandas.Series.resample().

314 questions
21
votes
4 answers

Pandas resample with start date

I'd like to resample a pandas object using a specific date (or month) as the edge of the first bin. For instance, in the following snippet I'd like my first index value to be 2020-02-29 and I'd be happy specifying start=2 or start="2020-02-29". >>>…
jsignell
  • 3,072
  • 1
  • 22
  • 23
12
votes
2 answers

Pandas df.resample with column-specific aggregation function

With pandas.DataFrame.resample I can downsample a DataFrame: df.resample("3s", how="mean") This resamples a data frame with a datetime-like index such that all values within 3 seconds are aggregated into one row. The values of the columns are…
knub
  • 3,892
  • 8
  • 38
  • 63
9
votes
1 answer

similar to pandas.resample but in node.js [danfo.js]

I am new to node.js and I am looking for a way to mimick the output of pandas.resample(‘3H’, label=’right’, closed=’left’).max() working with timeseries, being able to obtain a dataframe-like structure with the maximum value that happened in blocks…
9
votes
3 answers

Pandas: resample a dataframe to match a DatetimeIndex of a different dataframe

I have a two time series in separate pandas.dataframe, the first one - series1 has less entries and different start datatime from the second - series2: index1 = pd.date_range(start='2020-06-16 23:16:00', end='2020-06-16 23:40:30', freq='1T') series1…
Ohm
  • 2,312
  • 4
  • 36
  • 75
9
votes
1 answer

Resample Pandas Dataframe Without Filling in Missing Times

Resampling a dataframe can take the dataframe to either a higher or lower temporal resolution. Most of the time this is used to go to lower resolution (e.g. resample 1-minute data to monthly values). When the dataset is sparse (for example, no…
tnknepp
  • 5,888
  • 6
  • 43
  • 57
5
votes
1 answer

Pandas: resample hourly values to monthly values with offset

I want to aggregate a pandas.Series with an hourly DatetimeIndex to monthly values - while considering the offset to midnight. Example Consider the following (uniform) timeseries that spans about 1.5 months. import pandas as pd hours = pd.Series(1,…
ElRudi
  • 2,122
  • 2
  • 18
  • 33
5
votes
3 answers

pandas: resample a multi-index dataframe

I have a dataframe with a multi-index: "subject" and "datetime". Each row corresponds to a subject and a datetime, and columns of the dataframe correspond to various measurements. The range of days differ per subject and some days can be missing for…
4
votes
1 answer

Fill Gaps in time series pandas dataframe

I have a pandas dataframe with gaps in time series. It looks like the following: Example Input -------------------------------------- Timestamp Close 2021-02-07 09:30:00 124.624 2021-02-07 09:31:00 124.617 2021-02-07 10:04:00 …
Chris Bauer
  • 63
  • 1
  • 6
4
votes
4 answers

Fill dates on dataframe within groups with same ending

This is what I have: df = pd.DataFrame({'item': [1,1,2,2,1,1], 'shop': ['A','A','A','A','B','B'], 'date': pd.to_datetime(['2018.01.'+ str(x) for x in [2,3,1,4,4,5]]), 'qty':…
Edo
  • 7,567
  • 2
  • 9
  • 19
4
votes
2 answers

Pandas upsampling does not include the 23 hours of last day in year

I have a time series dataframe with dates|weather information that looks like this: 2017-01-01 5 2017-01-02 10 . . 2017-12-31 6 I am trying to upsample it to hourly data using the following: weather.resample('H').pad() I expected to see 8760…
4
votes
2 answers

Panda time series resample + adjusting values linearly

Using python and pandas, how do I resample a time series to even 5-min intervals (offset=zero min from whole hours) while also adjusting the values linearly? Hence, I want to turn this: value 00:01 2 00:05 10 00:11 22 00:14 …
Blue Demon
  • 293
  • 3
  • 12
4
votes
3 answers

Pandas Resampling Hourly OHLC to Daily OHLC

I have a dataframe of hourly OHLC as follows (please ignore the values of OHLC, I typed them in for better illustration), hr_df = Close High Low Open 2017-09-04 05:00:00 0.715035 0.715035 0.715035 …
Denzel
  • 358
  • 5
  • 19
3
votes
3 answers

Resample a data frame into n-month periods with arbitrary end-of-period months

I want to resample() my daily data into six-month chunks. However, I want the ends of the six-month chunks to be the ends of April and October. If I use df.resample('6M').sum() (or df.groupby(pd.Grouper(freq='6M').sum()), the end of the first…
Richard Herron
  • 9,760
  • 12
  • 69
  • 116
3
votes
1 answer

Custom intervals for pandas.resample (or groupby)

Let's say that I start with this dataframe d = {'price': [10, 12, 8, 12, 14, 18, 10, 20], 'volume': [50, 60, 40, 100, 50, 100, 40, 50]} df = pd.DataFrame(d) df['a_date'] = pd.date_range('01/01/2018', periods=8, …
duff18
  • 672
  • 1
  • 6
  • 19
3
votes
2 answers

Pandas: how to fill missing data with a mean value?

I read from a remote device some data every 5 seconds. They are saved as: 2018-01-01 00:00:00 2 2018-01-01 00:00:05 3 2018-01-01 00:00:10 3 2018-01-01 00:00:15 2 2018-01-01 00:00:20 3 2018-01-01 00:00:25 4 2018-01-01…
Alex Poca
  • 2,406
  • 4
  • 25
  • 47
1
2 3
20 21