# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# %matplotlib inline
import csv
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

records = pd.read_csv('../../data/fucking_final_dataset.csv')

records.head(1)

plt.rcParams['figure.figsize'] = (16.0, 8.0)

records.groupby('title_auth_slug').count()['control_number'].sort_values(inplace=False, ascending=False).ix[:50].plot(kind="bar")

len(records.groupby('title_auth_slug').count()['control_number'])

# +
d = {k: len(v) for k, v in records.groupby("title_auth_slug").groups.items()}

def prob_dist(d):
    probs = {}
    for k, v in d.items():
        probs.setdefault(v, 0)
        probs[v] += 1
    return probs


probs = prob_dist(d)
# -

plt.rcParams['figure.figsize'] = (12.0, 8.0)

plt.xscale("log")
plt.yscale("log")
plt.scatter(list(probs.keys()), list(probs.values()))

top_slugs = records.groupby('title_auth_slug').count()['control_number'].sort_values(inplace=False, ascending=False).ix[:1000].index

top_slugs

top_producers = records[records.title_auth_slug.isin(top_slugs)]

group_top_producers = top_producers.sort_values('pub_year').groupby(['title_auth_slug', 'pub_year']).count()['control_number']

top_producer_df1 = pd.DataFrame({
    'el ingenioso hidalgo don quijote de la mancha|cervantes saavedra, miguel de': group_top_producers.ix['el ingenioso hidalgo don quijote de la mancha|cervantes saavedra, miguel de'],
    'el lazarillo de tormes': group_top_producers.ix['novelas ejemplares,cervantes saavedra, miguel de'],
    'novelas ejemplares|cervantes saavedra, miguel de': group_top_producers.ix['don quijote de la mancha,cervantes saavedra, miguel de'],
    'don quijote de la mancha|cervantes saavedra, miguel de' group_top_producers.ix['<NAME>,hernandez, jose'],
    '<NAME>|hernandez, jose': group_top_producers.ix['la celestina,rojas, fernando de'],
    'la iliada|homer': group_top_producers.ix['libro de buen amor,ruiz, juan'],
    'la divina comedia|dante alighieri': group_top_producers.ix['la isla del tesoro,stevenson, <NAME>'],
    'la isla del tesoro|stevenson, <NAME>': group_top_producers.ix['constitucion politica de los estados unidos mexicanos,mexico'],
    'la celestina|rojas, fernando de': group_top_producers.ix['la vida es sueno,calderon de la barca, pedro'],
    'poema de mio cid,nan': group_top_producers.ix['poema de mio cid,nan'],
#     'orlando furioso|ariosto, lodovico': group_top_producers.ix['orlando furioso|ariosto, lodovico']
    }).fillna(0)

# +
# Looking at orlando and the celestina
# -

top_16th = records.sort_values('pub_year').groupby(['title_auth_slug', 'pub_year']).count()['control_number']

top_16th.ix['tragicomedia de calisto y melibea. enla ql se cotiene de mas de su agradable dulce estilo muchas sentencias filosofales: auisosmuy necessarios a macebos ... nueuamente anadido el tractado de centurio. [with woodcuts.] g.l']

top_16th.ix['tragicomedia de calisto y melibea|rojas, fernando de']

top_16th.ix['la celestina|rojas, fernando de']



top_producer_df1.plot()

top_producer_df2 = pd.DataFrame({
    'lazarillo de tormes,nan': group_top_producers.ix['lazarillo de tormes,nan'],
    'la divina comedia,dante alighieri': group_top_producers.ix['la divina comedia,dante alighieri'],
    'maria,isaacs, jorge': group_top_producers.ix['maria,isaacs, jorge'],
    '<NAME>,valera, juan': group_top_producers.ix['pep<NAME>,valera, juan'],
    'el principe,machiavelli, niccolo': group_top_producers.ix['el principe,machiavelli, niccolo'],
    '<NAME>,defoe, daniel': group_top_producers.ix['<NAME>,defoe, daniel'],
    'marianela,perez galdos, benito': group_top_producers.ix['marianela,perez galdos, benito'],
    'don segundo sombra,guiraldes, ricardo': group_top_producers.ix['don segundo sombra,guiraldes, ricardo'],
    'episodios nacionales,perez galdos, benito': group_top_producers.ix['episodios nacionales,perez galdos, benito'],
    'rimas,becquer, gustavo adolfo': group_top_producers.ix['rimas,becquer, gustavo adolfo'],
}).fillna(0)

top_producer_df2.plot()

top_producer_df3 = pd.DataFrame({
    'sagrada biblia,nan': group_top_producers.ix['sagrada biblia,nan'],
    'la regenta,alas, leopoldo': group_top_producers.ix['la regenta,alas, leopoldo'],
    'fausto,goethe, <NAME>': group_top_producers.ix['fausto,goethe, <NAME>'],
    'rimas y leyendas,becquer, gustavo adolfo': group_top_producers.ix['rimas y leyendas,becquer, gustavo adolfo'],
    'summa artishistoria general del arte,pijoan, jose': group_top_producers.ix['summa artishistoria general del arte,pijoan, jose'],
    'cien anos de soledad,<NAME>, gabriel': group_top_producers.ix['cien anos de soledad,<NAME>, gabriel'],
    'alicia en el pais de las maravillas,carroll, lewis': group_top_producers.ix['alicia en el pais de las maravillas,carroll, lewis'],
    'historia verdadera de la conquista de la nueva espana,diaz del castillo, bernal': group_top_producers.ix['historia verdadera de la conquista de la nueva espana,diaz del castillo, bernal'],
    'derecho civil espanol, comun y foral,castan tobenas, jose': group_top_producers.ix['derecho civil espanol, comun y foral,castan tobenas, jose'],
    'obras completas,ortega y gasset, jose': group_top_producers.ix['obras completas,ortega y gasset, jose'],
}).fillna(0)

# +
# top_producer_df3.plot()
# -

top_producer_df4 = pd.DataFrame({
    'los tres mosqueteros,dumas, alexandre': group_top_producers.ix['los tres mosqueteros,dumas, alexandre'],
    'mujercitas,alcott, <NAME>': group_top_producers.ix['mujercitas,alcott, <NAME>'],
    'la voragine,rivera, <NAME>': group_top_producers.ix['la voragine,rivera, <NAME>'],
    '<NAME>,bronte, emily': group_top_producers.ix['cumbres borrascosas,bronte, emily'],
    'el principito,saint-exupery, antoine de': group_top_producers.ix['el principito,saint-exupery, antoine de'],
    '<NAME>,zorrilla, jose': group_top_producers.ix['<NAME>,zorrilla, jose'],
    '<NAME>,gallegos, romulo': group_top_producers.ix['dona barbara,gallegos, romulo'],
    'el conde lucanor,<NAME>': group_top_producers.ix['el conde lucanor,<NAME>'],
    'os lusiadas,camoes, luis de': group_top_producers.ix['os lusiadas,camoes, luis de'],
    'entremeses,cervantes saavedra, miguel de': group_top_producers.ix['entremeses,cervantes saavedra, miguel de'],
    'las aventuras de tom sawyer,twain, mark': group_top_producers.ix['las aventuras de tom sawyer,twain, mark'],
}).fillna(0)

top_producer_df4.plot()

top_producer_df5 = pd.DataFrame({
    '': group_top_producers.ix[''],
    '': group_top_producers.ix[''],
    '': group_top_producers.ix[''],
    '': group_top_producers.ix[''],
    '': group_top_producers.ix[''],
    '': group_top_producers.ix[''],
    '': group_top_producers.ix[''],
    '': group_top_producers.ix[''],
    '': group_top_producers.ix[''],
    '': group_top_producers.ix[''],
}).fillna(0)

# +
# top_producer_df5.plot()

StarcoderdataJupyterScriptsDedupFiltered