Skip to content

Instantly share code, notes, and snippets.

@arunsrin
Created October 17, 2016 10:05
Show Gist options
  • Save arunsrin/f712297423f2baae6065373879ac64c0 to your computer and use it in GitHub Desktop.
Save arunsrin/f712297423f2baae6065373879ac64c0 to your computer and use it in GitHub Desktop.
librarything stats
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 27 15:34:55 2016
@author: arunsrin
"""
import csv
from bokeh.plotting import output_file, show
from bokeh.charts import Bar
import pandas as pd
# initialize
LT_FILE='librarything_indeliblestamp.tsv' #librarything tab-delimited dump
output_file("lt.html")
x = []
y = []
dates = []
# create x-axis labels (2009-01, 2009-02 and so on)
for year in range(2009,2017):
for month in range(1,13):
dates.append("%s-%02d" % (year, month))
y.append(0)
# create x-axis indices
for count in range(len(dates)):
x.append(count)
# create y-axis content: a count of books bought in a particular month
with open(LT_FILE,'r') as csvfile:
plots = csv.reader(csvfile, delimiter='\t')
for cur_row in plots:
for count, date in enumerate(dates):
if date in cur_row[41]:
y[count]=y[count]+1
# create panda dataframe with these 3 lists
barchart_data = pd.DataFrame({'x' : x,
'y' : y,
'dates': dates
})
# create bar chart
p = Bar(barchart_data, 'dates', values='y', title="My Books",
xlabel="Month", ylabel="Books Bought", legend=None,
plot_width=1500)
show(p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment