Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Pandas: Resample date range

Tags:

python

pandas

I create a list of pandas datetimes with the following line:

range = pd.date_range(start = '5/3/2005', periods =5+1, freq='1D')

Is there a quick way to resample that list so that it spans the same range but with a frequency of 30 min? (so far I can only see applications of that logic to Series or DataFrames index, but no daterange)

like image 221
jim jarnac Avatar asked Sep 20 '26 22:09

jim jarnac


2 Answers

One way is:

date_range = pd.date_range(start = '5/3/2005', periods =5+1, freq='1D')
new_date_range = date_range.to_series().asfreq('30 min').index

Also, range is a builtin function, so I would not call the variable "range".

I hope this helps.

like image 154
Abdou Avatar answered Sep 23 '26 12:09

Abdou


You could also do

date_range = pd.date_range(start = '5/3/2005', periods =5+1, freq='1D')
new_date_range = pd.date_range(date_range.min(), date_range.max(), freq='30 min')
like image 26
piRSquared Avatar answered Sep 23 '26 10:09

piRSquared



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!