Last active
January 15, 2020 15:38
-
-
Save nim4n136/1db7d674a3a20c4f8f6f7a1a10410c12 to your computer and use it in GitHub Desktop.
date_range_split_cluster
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from datetime import datetime | |
| import pandas as pd | |
| from sys import argv | |
| def split_date_range(stdate, fndate, periods): | |
| def date_object(string): | |
| return datetime.strptime(string, '%Y-%m-%d') | |
| stdate = date_object(stdate) | |
| fndate = date_object(fndate) | |
| date_range = pd.date_range(stdate, fndate, periods=12) | |
| range_list = [] | |
| temp_list = [] | |
| count = 0 | |
| for range in date_range: | |
| if count >= 2: | |
| count = 0 | |
| range_list.append(temp_list) | |
| temp_list = [] | |
| count = count+1 | |
| temp_list.append(range.strftime('%Y-%m-%d')) | |
| return range_list | |
| date_cluster = split_date_range('2019-01-01', '2020-01-12', 4) | |
| for date in date_cluster: | |
| print(date[0], date[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment