In [14]:
import pandas as pd

In [15]:
df = pd.read_csv("citySummons.csv", names=["type","mtd","ytd","date"])
chart = df[["date","type","mtd"]].sort(['date', 'type'])

In [16]:
chart = chart[chart.type != "TOTAL Movers"]

In [18]:
gchart = chart.groupby('date')

In [19]:
rows = []
for name, group in gchart:
    tdict = {"c":[{"v": name}]}
    for idx, row in group.iterrows():
        tdict["c"].append({"v":row['mtd']})
    rows.append(tdict)

In [20]:
cols = [{"id": "date", "label":"Date", "type":"string"}]
for row in gchart.get_group('2012_02')['type']:
    cols.append({"id":row, "label":row, "type":"number"})

In [30]:
chart = {
  "type": "AreaChart",
  "cssStyle": "height:900px; width:1600px;",
  "data": { "cols": [], "rows":[]},
  "options": {
    "title": "Sales per month",
    "isStacked": "true",
    "fill": 20,
    "displayExactValues": True,
    "vAxis": {
      "title": "Sales unit",
      "gridlines": {"count": 6}
    },
    "hAxis": {"title": "Date"}
    },
  "formatters": {},
  "displayed": True
}

In [31]:
chart['data']['cols'] = cols
chart['data']['rows'] = rows

In [32]:
import json

In [33]:
json.dump(chart,open('/var/www/visionzero/appFolder/static/summons.json','wb'))

In [ ]: