<jupyter_start><jupyter_text><jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
# Web scrapping
import requests
from bs4 import BeautifulSoup
import lxml.html as lh<jupyter_output><empty_output><jupyter_text>Datos: https://github.com/MinCiencia/Datos-COVID19/tree/master/output/producto55<jupyter_code>data_raw = pd.read_csv("https://raw.githubusercontent.com/MinCiencia/Datos-COVID19/master/output/producto55/Positividad_por_comuna.csv")
data_raw.head()
data_raw["Region"].unique()
data_RM = data_raw.query("Region == 'Metropolitana'")
data_RM = data_RM.drop(columns=["Region", "Codigo region"])
data_RM["fecha"] = pd.to_datetime(data_RM["fecha"])
first_date, last_date = data_RM["fecha"].sort_values().iloc[0], data_RM["fecha"].sort_values().iloc[-1]
first_date, last_date
dates = pd.date_range(start=first_date, end=last_date)<jupyter_output><empty_output><jupyter_text>Datos: https://es.wikipedia.org/wiki/Anexo:Comunas_de_Santiago_de_ChileConurbaci%C3%B3n_de_Santiago<jupyter_code>url = "https://es.wikipedia.org/wiki/Anexo:Comunas_de_Santiago_de_Chile#Conurbaci%C3%B3n_de_Santiago"
res = requests.get(url).text
soup = BeautifulSoup(res,'lxml')
soup.prettify()
table = soup.find('table',{'class':'wikitable sortable'}).find_all('tr')[1:]
#We create a DataFrame of the Santiago neighborhood's according to wikipedia:
df_stgo = pd.DataFrame(columns = ['Comuna','Sector'], index = None)
for items in table:
    data = items.find_all(['th','td'])
    name = data[0].text
    borough = data[1].text
    df_stgo = df_stgo.append({'Comuna':name,
                              'Sector':borough}, ignore_index = True)
df_stgo
data = pd.DataFrame()
data["fecha"] = dates
data = data.set_index("fecha")
for comuna in data_RM["Comuna"].unique():
    data[comuna] = data_RM.query(f"Comuna == '{comuna}'").drop(columns=["Comuna", "Codigo comuna"]).set_index("fecha")["positividad"]
data.tail()
fig, ax = plt.subplots(figsize=(10,10))
for comuna in df_stgo["Comuna"]:
    if comuna in list(df_stgo[df_stgo["Sector"] == 'nororiente']["Comuna"]):
        ax.plot(data[comuna].index, 100*data[comuna],color="blue", alpha=0.3)
    else:
        ax.plot(data[comuna].index, 100*data[comuna],color="red", alpha=0.2)
    
ax.plot(data["Vitacura"].index, 100*data["Vitacura"],color="blue", alpha=0.2, label="sector nororiente")
ax.plot(data["Santiago"].index, 100*data["Santiago"],color="red", alpha=0.2, label="otros sectores")
# Format the x axis with centered month labels
ax.xaxis.set_major_locator(mdates.MonthLocator())
ax.xaxis.set_minor_locator(mdates.MonthLocator(bymonthday=15))
ax.xaxis.set_major_formatter(plt.NullFormatter())
ax.xaxis.set_minor_formatter(mdates.DateFormatter('%h'));
ax.legend(fontsize="large")
ax.set_yticks([10*i for i in range(7)])
ax.set_yticklabels([f"{10*i}%" for i in range(7)])
ax.set_title("Positividad Test PCR (%) en la conurbación de Santiago", fontsize=20)
ax.set_ylabel("Positividad de test PCR", fontsize=15)
plt.annotate('Fuente: https://www.icovidchile.cl/', (0,0), (-40,-30), xycoords='axes fraction', textcoords='offset points', va='top', fontsize="x-large")
plt.savefig('2020-09-08-Positividad.png', bbox_inches='tight', format='png', dvi=8000)
# plt.show()
from google.colab import files
files.download("2020-09-08-Positividad.png")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17127564674397858, 'fraction_numerical': 0.023788284269997028, 'mean_word_length': 7.0095238095238095, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 5, 'lorem ipsum': 0, 'www.': 1, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '322442', 'license': 'MIT', 'n_tokens_mistral': 1341, 'n_tokens_neox': 1272, 'n_words': 194, 'path': 'Positividad_conurbacion_de_Santiago.ipynb', 'repo_name': 'alonsosilvaallende/Desigualdad-Covid19', 'size': '3363'}