Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def month_to_number(month_string): # Returns the zero padded number of a Dutch month
- handlers = {"januari": 1,
- "februari": 2,
- "maart": 3,
- "april": 4,
- "mei": 5,
- "juni": 6,
- "juli": 7,
- "augustus": 8,
- "september": 9,
- "oktober": 10,
- "november": 11,
- "december": 12}
- return '{:02d}'.format(handlers[month_string]) # Return a string of a zero padded int
- def string_to_datetime(string_date): # Returns a datetime object from a custom time format, e.g "vrijdag 19 juni 2015" -> datetime object
- string_date_without_day = " ".join(string_date.split()[1:]) # Splits string_date and joins it from [1:]
- string_date_numbers = "{day}-{month}-{year}".format(day = string_date_without_day.split()[0], month = month_to_number(string_date_without_day.split()[1]), year = string_date_without_day.split()[2])
- return datetime.strptime(string_date_numbers, "%d-%m-%Y")
- cur.execute("SELECT * FROM history")
- for info_tuple in cur.fetchall():
- dates.append(string_to_datetime(info_tuple[0]))
- if ", " in str(info_tuple[2]): # I couldn't put a list in an SQLite3 database, so I used ", ".join([1, 2, 3]). This code appends the length of the list to the list free
- free.append(len(info_tuple[2].split(", ")))
- else:
- free.append(len(str(info_tuple[2])))
- if ", " in str(info_tuple[3]): # Same as above, but for change
- change.append(len(info_tuple[3].split(", ")))
- else:
- change.append(len(str(info_tuple[3])))
- if ", " in str(info_tuple[4]): # Same as above, but for star
- star.append(len(info_tuple[4].split(", ")))
- else:
- star.append(len(str(info_tuple[4])))
- df = pd.DataFrame({"Datum": dates, "Vrij": free, "Roosterwijziging": change, "Steruur": star})
- df.plot(x = "Datum", y = ["Vrij", "Roosterwijziging", "Steruur"])
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement