Created
April 25, 2020 01:19
-
-
Save robintux/c140ba9cdf62d6b8be1b8d7c826ac1aa to your computer and use it in GitHub Desktop.
Ejemplo creado gracias a las respuestas dadas en reddit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from datetime import datetime, timedelta | |
import matplotlib.pyplot as plt | |
from matplotlib.dates import DateFormatter | |
import matplotlib.dates as mdates | |
import numpy as np | |
%matplotlib auto | |
data = pd.read_csv("https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-andamento-nazionale/dpc-covid19-ita-andamento-nazionale.csv") | |
print (data.columns) | |
data['diff_deceduti'] = data['deceduti'].diff() | |
data['diff_tamponi'] = data['tamponi'].diff() | |
dates = data['data'] | |
date_format = [pd.to_datetime(d) for d in dates] | |
# Añadimos una columna con el nombres del dia | |
# https://stackoverflow.com/questions/30222533/create-a-day-of-week-column-in-a-pandas-dataframe-using-python | |
data['data'] = pd.to_datetime(data['data']) | |
data['dia'] = data['data'].dt.day_name() | |
# Agregamos una columna con el nombre del mes | |
# https://stackoverflow.com/questions/37625334/python-pandas-convert-month-int-to-month-name | |
data['mes'] = data['data'].dt.month_name() | |
# Visualizacion | |
# LOs dias lunes y viernes se pintan de color diferente al resto de dias | |
variable = 'nuovi_positivi' | |
fig, ax = plt.subplots(figsize=(12, 5)) | |
ax.grid() | |
# | |
colores = np.where(data.dia=="Monday", 'k', np.where(data.dia=="Friday",'b','r')) | |
# | |
ax.scatter(date_format,data[variable], c = colores) | |
ax.set(xlabel="Date",ylabel=variable,title=variable) | |
date_form = DateFormatter("%d-%m") | |
ax.xaxis.set_major_formatter(date_form) | |
ax.xaxis.set_major_locator(mdates.DayLocator(interval = 3)) | |
fig.savefig(variable + '.png') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment