Skip to content

Instantly share code, notes, and snippets.

@bruno-uy
Last active May 18, 2021 14:03
Show Gist options
  • Save bruno-uy/9a58cd15771bfc7b3f4fe7f18d5a0d0d to your computer and use it in GitHub Desktop.
Save bruno-uy/9a58cd15771bfc7b3f4fe7f18d5a0d0d to your computer and use it in GitHub Desktop.
Date intervals evenly distributed between dates
import pandas as pd
# The function shows `str` for dates, but could be datetime.date objects as well
def n_date_intervals(start_date: str, end_date: str, intervals_count: int) -> pd.Series:
return pd.Series(pd.date_range(start_date, end_date, periods=intervals_count))
# Change this variables as needed
start_date = "2018-01-01"
end_date = "2021-03-24"
intervals_count = 5
# Print result in ISO format
result = n_date_intervals(start_date, end_date, intervals_count)
for ts in result:
print(ts.isoformat())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment