Created
February 16, 2018 12:27
-
-
Save zeffii/4cf8519d2e670de20f2a10c67d606cfd to your computer and use it in GitHub Desktop.
csv data point interpolator stepwise
This file contains 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, date, timedelta | |
csv = """\ | |
12/08/2017,34 | |
13/08/2017,38 | |
23/08/2017,39 | |
03/09/2017,34 | |
13/09/2017,32 | |
02/10/2017,30 | |
""" | |
date_format = "%d/%m/%Y" | |
csv_data = [] | |
for item in csv.splitlines(): | |
k, v = item.split(',') | |
csv_data.append((k, int(v))) | |
csv_data_dict = {date: insuline for date, insuline in csv_data} | |
def generate_interpolation_data(csv_data): | |
start = csv_data[0][0] | |
end = csv_data[-1][0] | |
a = datetime.strptime(start, date_format) | |
b = datetime.strptime(end, date_format) | |
delta = b - a | |
num_days = delta.days | |
insuline = 0 | |
for i in range(delta.days + 1): | |
day = a + timedelta(days=i) | |
day_str = day.strftime(date_format) | |
insuline = csv_data_dict.get(day_str, insuline) | |
print(day_str, insuline) | |
generate_interpolation_data(csv_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment