Skip to content

Instantly share code, notes, and snippets.

@AO8
Last active September 26, 2018 17:11
Show Gist options
  • Select an option

  • Save AO8/46c39bfefa7bccd5f163a594f336b07f to your computer and use it in GitHub Desktop.

Select an option

Save AO8/46c39bfefa7bccd5f163a594f336b07f to your computer and use it in GitHub Desktop.
Another approach to an ongoing Python project: reading CSV exported from Calendly to analyze what months students book an advising appointment. Key modules used in this approach include OrderedDict, datetime, and matplotlib.
import csv
from datetime import datetime
from collections import OrderedDict
import matplotlib.pyplot as plt
# set up empty containers
total = 0
months = dict()
# open and read CSV
with open("dashboard-export.csv") as f:
csv_reader = csv.reader(f)
headings = next(csv_reader)
#convert DATE field to a datetime object and add to months dict
for row in csv_reader:
d = row[6].split("/")
d_obj = datetime(year=int(d[2][0:5]), month=int(d[0]), day=int(d[1]))
d_obj_month = d_obj.strftime("%B")
if d_obj_month not in months:
months[d_obj_month] = 1
else:
months[d_obj_month] += 1
# create sorted containers
months_list = sorted(months, key=lambda month: datetime.strptime(month, "%B"))
months_tuples = [(key, months[key]) for key in months_list]
sorted_months_dict = OrderedDict(months_tuples)
# calculate totals and print results
for v in sorted_months_dict.values():
total += v
for k,v in sorted_months_dict.items():
print(f"{k} = {v}")
print(f"\ntotal = {total}")
# create lists from dictionary for plotting
appointments = [key for key in sorted_months_dict.keys()]
values = [value for value in sorted_months_dict.values()]
plt.plot(values, color="green")
plt.ylabel("Number of Appts Booked", weight="bold", size="large")
plt.xticks(range(len(values)), appointments, rotation=50, horizontalalignment="right", weight="bold", size="large")
plt.yticks(weight="bold", size="large")
plt.title("Months student book a BAS-SD advising appt with AO", size="large", weight="bold")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment