Skip to content
Advertisement

How to use pd.data_range() with a frequency of X minutes/hours/seconds?

I need to create a frequent date range with pandas date_range(). This works well with frequency=... parameter. But sometimes my code needs these frequent ranges in longer frequencys. for example 4 Hours or 5 minutes instead of one.

How can I do that with pd.date_range(first_X_datetime, last_X_datetime, freq=frequency)?

If there is not a more efficient way, my idea would be to create a pd.date_range and then drop the unincluded indices. But how to do that ? (currently i cant think of a better approach)

Advertisement

Answer

You can always customize the frequency as you wish instead of only 1 hour or 1 minute.

JavaScript

Please check it out here for more information:

https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#timeseries-offset-aliases

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.date_range.html

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement