In [1]:
%matplotlib inline
import csv
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
In [2]:
records = pd.read_csv('../data/fucking_final_dataset.csv')
records = records[records.pub_year > 1599]
records = records[records.pub_year < 1700]
In [3]:
len(records)
Out[3]:
In [4]:
records.head(1)
Out[4]:
In [5]:
plt.rcParams['figure.figsize'] = (12.0, 6.0)
In [6]:
records.groupby('canonical_country').count()['control_number'].sort_values(inplace=False, ascending=False).ix[:10].plot(kind="bar")
Out[6]:
In [7]:
records.groupby('slug').count()['control_number'].sort_values(inplace=False, ascending=False).ix[:25].plot(kind="bar")
Out[7]:
In [8]:
records.sort_values('pub_year').groupby('pub_year').count()['control_number'].plot()
Out[8]:
In [9]:
# records[records.pub_year < 1900].sort_values('pub_year').groupby('pub_year').count()['control_number'].plot()
In [10]:
# records[records.pub_year > 1900].sort_values('pub_year').groupby('pub_year').count()['control_number'].plot()
In [19]:
top_slugs = records.groupby('slug').count()['control_number'].sort_values(inplace=False, ascending=False).ix[:12].index
In [20]:
top_producers = records[records.slug.isin(top_slugs)]
In [21]:
group_top_producers = top_producers.sort_values('pub_year').groupby(['slug', 'pub_year']).count()['control_number']
In [28]:
top_producer_df = pd.DataFrame({
'madrid,spain': group_top_producers.ix['madrid,spain'],
'barcelona,spain': group_top_producers.ix['barcelona,spain'],
'lisbon,portugal': group_top_producers.ix['lisbon,portugal'],
'sevilla,spain': group_top_producers.ix['sevilla,spain'],
'zaragoza,spain': group_top_producers.ix['zaragoza,spain'],
# 'valencia,spain': group_top_producers.ix['valencia,spain'],
# 'mexico,mexico': group_top_producers.ix['mexico,mexico'],
# 'valladolid,spain': group_top_producers.ix['valladolid,spain'],
# 'salamanca,spain': group_top_producers.ix['salamanca,spain'],
# 'granada,spain': group_top_producers.ix['granada,spain'],
})
top_producer_df = top_producer_df.fillna(0)
In [29]:
top_producer_df.plot()
Out[29]:
In [25]:
counted_by_year = records.sort_values('pub_year').groupby('pub_year').count()['control_number']
In [26]:
top_producer_df_percent = pd.DataFrame({
'madrid,spain': top_producer_df['madrid,spain'].divide(counted_by_year.values),
'barcelona,spain': top_producer_df['barcelona,spain'].divide(counted_by_year.values),
'lisbon,portugal': top_producer_df['lisbon,portugal'].divide(counted_by_year.values),
'sevilla,spain': top_producer_df['sevilla,spain'].divide(counted_by_year.values),
'zaragoza,spain': top_producer_df['zaragoza,spain'].divide(counted_by_year.values),
# 'valencia,spain': top_producer_df['valencia,spain'].divide(counted_by_year.values),
# 'mexico,mexico': top_producer_df['mexico,mexico'].divide(counted_by_year.values),
# 'valladolid,spain': top_producer_df['valladolid,spain'].divide(counted_by_year.values),
# 'salamanca,spain': top_producer_df['salamanca,spain'].divide(counted_by_year.values),
# 'granada,spain': top_producer_df['granada,spain'].divide(counted_by_year.values),
})
In [27]:
top_producer_df_percent.plot.area(stacked=False)
Out[27]:
In [41]:
america = records[records.slug.isin(['lima,peru', 'mexico,mexico'])].\
sort_values('pub_year').groupby(['slug', 'pub_year']).count()['control_number']
In [45]:
pd.DataFrame({'lima': america.ix['lima,peru'], 'mexico': america.ix['mexico,mexico']}).fillna(0).plot()
Out[45]:
In [ ]: