Documentos de Académico
Documentos de Profesional
Documentos de Cultura
LAB SEM 3 GRUPO H PRIMER PARTE Ver 1 1 Finish
LAB SEM 3 GRUPO H PRIMER PARTE Ver 1 1 Finish
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import pandas
<IPython.core.display.HTML object>
Saving fallecidos_covid19_Corregido.csv to
fallecidos_covid19_Corregido.csv
data=pd.read_csv("fallecidos_covid19_Corregido.csv",sep=';',encoding='
latin-1')
data.describe()
Riesgo_distrito Nombre_Año
count 44201.000000 44201.000000
mean 2.493337 2020.510848
std 1.118502 0.499888
min 1.000000 2020.000000
25% 1.000000 2020.000000
50% 2.000000 2021.000000
75% 3.000000 2021.000000
max 4.000000 2021.000000
data.head()
Nombre_Dia Nombre_Año
0 lunes 2020
1 viernes 2021
2 miércoles 2021
3 viernes 2020
4 miércoles 2021
data.tail()
data.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 44201 entries, 0 to 44200
Data columns (total 15 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 DEPARTAMENTO 44201 non-null object
1 PROVINCIA 44201 non-null object
2 DISTRITO 44201 non-null object
3 SEXO 44201 non-null object
4 Year 44201 non-null int64
5 Month 44201 non-null int64
6 Day 44201 non-null int64
7 contar_fall 44201 non-null int64
8 METODODX 44201 non-null object
9 contar_pos 44201 non-null int64
10 Riesgo_distrito 44201 non-null int64
11 Fecha 44201 non-null object
12 Nombre_Mes 44201 non-null object
13 Nombre_Dia 44201 non-null object
14 Nombre_Año 44201 non-null int64
dtypes: int64(7), object(8)
memory usage: 5.1+ MB
data.columns
sns.heatmap(data.isnull(),yticklabels=False,cbar=False,cmap='viridis')
<AxesSubplot:>
data.isnull().sum()
DEPARTAMENTO 0
PROVINCIA 0
DISTRITO 0
SEXO 0
Year 0
Month 0
Day 0
contar_fall 0
METODODX 0
contar_pos 0
Riesgo_distrito 0
Fecha 0
Nombre_Mes 0
Nombre_Dia 0
Nombre_Año 0
dtype: int64
superdepartamento=pd.value_counts(data['DEPARTAMENTO'])
superdepartamento
AREQUIPA 4424
PIURA 4204
LA LIBERTAD 3575
JUNIN 3271
ICA 2987
LAMBAYEQUE 2967
LIMA REGION 2800
CALLAO 2623
ANCASH 2358
CUSCO 2034
CAJAMARCA 1577
LORETO 1358
SAN MARTIN 1266
PUNO 1252
UCAYALI 1246
TACNA 1025
HUANUCO 978
AYACUCHO 789
MOQUEGUA 673
APURIMAC 585
TUMBES 573
AMAZONAS 508
PASCO 396
MADRE DE DIOS 378
HUANCAVELICA 354
Name: DEPARTAMENTO, dtype: int64
super=pd.value_counts(data['PROVINCIA'])
super
AREQUIPA 3836
CALLAO 2623
TRUJILLO 2543
PIURA 2258
CHICLAYO 2193
...
PAUCARTAMBO 1
CANDARAVE 1
VILCAS HUAMAN 1
SUCRE 1
ANTONIO RAIMONDI 1
Name: PROVINCIA, Length: 186, dtype: int64
super=pd.value_counts(data['SEXO'])
super
MASCULINO 23504
FEMENINO 20697
Name: SEXO, dtype: int64
super=pd.value_counts(data['Nombre_Mes'])
super
Mayo 6434
Junio 6132
Abril 5748
Agosto 4850
Julio 4515
Marzo 4152
Febrero 4056
Enero 2761
Setiembre 2552
Octubre 1269
Diciembre 917
Noviembre 815
Name: Nombre_Mes, dtype: int64
super=pd.value_counts(data['Nombre_Año'])
super
2021 22580
2020 21621
Name: Nombre_Año, dtype: int64
#histograma departamento
plt.figure(figsize=(10,5))
sns.countplot(x='DEPARTAMENTO',data=data,palette='rainbow')
#rotar 90 grados
plt.xticks(rotation=90)
plt.show()
superdepartamento=pd.DataFrame(superdepartamento)
superdepartamento.columns=["Frec_abs"]
superdepartamento["Frec_rel_%"]=100*superdepartamento["Frec_abs"]/
len(data)
valor_ac=0
Frec_rel_val=superdepartamento["Frec_rel_%"].values
for i in Frec_rel_val:
valor_ac=valor_ac+i
superdepartamento
Frec_abs Frec_rel_%
AREQUIPA 4424 10.008823
PIURA 4204 9.511097
LA LIBERTAD 3575 8.088052
JUNIN 3271 7.400285
ICA 2987 6.757766
LAMBAYEQUE 2967 6.712518
LIMA REGION 2800 6.334698
CALLAO 2623 5.934255
ANCASH 2358 5.334721
CUSCO 2034 4.601706
CAJAMARCA 1577 3.567793
LORETO 1358 3.072329
SAN MARTIN 1266 2.864189
PUNO 1252 2.832515
UCAYALI 1246 2.818941
TACNA 1025 2.318952
HUANUCO 978 2.212620
AYACUCHO 789 1.785027
MOQUEGUA 673 1.522590
APURIMAC 585 1.323499
TUMBES 573 1.296351
AMAZONAS 508 1.149295
PASCO 396 0.895907
MADRE DE DIOS 378 0.855184
HUANCAVELICA 354 0.800887
'UCAYALI','TACNA','HUANUCO','AYACUCHO','MOQUEGUA','APURIMAC','TUMBES',
'AMAZONAS','PASCO','MADRE DE
DIOS','HUANCAVELICA'],autopct='%.2f',
title='DEPARTAMENTO',figsize=(20,20))
<AxesSubplot:title={'center':'DEPARTAMENTO'}, ylabel='Frec_rel_%'>
labels = ['AREQUIPA','PIURA','LA LIBERTAD','JUNIN','ICA','LAMBAYEQUE',
'LIMA
REGION','CALLAO','ANCASH','CUSCO','CAJAMARCA','LORETO','SAN
MARTIN','PUNO',
'UCAYALI','TACNA','HUANUCO','AYACUCHO','MOQUEGUA','APURIMAC','TUMBES',
'AMAZONAS','PASCO','MADRE DE
DIOS','HUANCAVELICA']
explode = [0.1,0.2,0.3,0.4,0.3,0.2,0.1,0.2,0.3,0.4,0.3,
0.2,0.1,0.2,0.3,0.4,0.3,0.2,0.1,0.2,0.3,0.4,0.3,
0.2,0.1]###diferencia del resto
colors = sns.color_palette('pastel')
plt.pie(superdepartamento['Frec_rel_%'], labels=labels,colors =
colors, autopct = '%0.0f%%',explode = explode)
plt.show()
plt.figure(figsize=(20, 20))
<Figure size 2000x2000 with 0 Axes>
2 11159
1 11120
4 11004
3 10918
Name: Riesgo_distrito, dtype: int64
super=pd.value_counts(data['contar_pos'])
super
1 14063
2 7387
3 4617
4 3007
5 2232
...
158 1
292 1
115 1
227 1
130 1
Name: contar_pos, Length: 147, dtype: int64
super=pd.value_counts(data['METODODX'])
super
PR 35277
AG 8924
Name: METODODX, dtype: int64
super=pd.DataFrame(super)
super.columns=["Frec_abs"]
super["Frec_rel_%"]=100*super["Frec_abs"]/len(data)
valor_ac=0
Frec_rel_val=super["Frec_rel_%"].values
for i in Frec_rel_val:
valor_ac=valor_ac+i
super
Frec_abs Frec_rel_%
PR 35277 79.810412
AG 8924 20.189588
super['Frec_rel_%'].plot(kind='pie',labels = ['PR',
'AG'],autopct='%.2f', title='METODODX',figsize=(10,10))
<AxesSubplot:title={'center':'METODODX'}, ylabel='Frec_rel_%'>
labels = ['PR', 'AG']
explode = [0.1,0.2]###diferencia del resto
colors = sns.color_palette('pastel')
plt.pie(super['Frec_rel_%'], labels=labels,colors = colors, autopct =
'%0.0f%%',explode = explode)
plt.show()
dato cualitativo ordinal
super=pd.value_counts(data['SEXO'])
super
MASCULINO 23504
FEMENINO 20697
Name: SEXO, dtype: int64
super=pd.DataFrame(super)
super.columns=["Frec_abs"]
super["Frec_rel_%"]=100*super["Frec_abs"]/len(data)
valor_ac=0
Frec_rel_val=super["Frec_rel_%"].values
acum=[]
for i in Frec_rel_val:
valor_ac=valor_ac+i
acum.append(valor_ac)
super["Frec_rel_%_acum"]= acum
super
Arguments:
ax (matplotlib.axes.Axes): The matplotlib object containing
the axes
of the plot to annotate.
spacing (int): The distance between the labels and the bars.
"""
plt.savefig("image.png")
sns.countplot(x="METODODX", hue="SEXO",data=data,palette='Set3')
<AxesSubplot:xlabel='METODODX', ylabel='count'>
plt.figure(figsize=(10,5))
sns.catplot(x="Nombre_Mes", hue="DEPARTAMENTO", col="SEXO",
data=data, kind="count",
height=4, aspect=1 )
plt.xticks(rotation=90)
plt.show()
<AxesSubplot:xlabel='contar_pos', ylabel='SEXO'>
plt.figure(figsize=(15, 10))
sns.boxplot(x = 'contar_fall', y = 'METODODX', data = data)
<AxesSubplot:xlabel='contar_fall', ylabel='METODODX'>
#cantidad de fallecidos por SEXO
plt.figure(figsize=(15, 10))
sns.boxplot(x = 'contar_fall', y = 'SEXO', data = data)
<AxesSubplot:xlabel='contar_fall', ylabel='SEXO'>
data.groupby(['DEPARTAMENTO','SEXO'])
['contar_fall'].sum().unstack().plot(kind='bar',stacked=True,figsize=(
15,10))
<AxesSubplot:xlabel='DEPARTAMENTO'>
#positivos por departamento
data.groupby(['DEPARTAMENTO','SEXO'])
['contar_pos'].sum().unstack().plot(kind='bar',stacked=True,figsize=(1
5,10))
<AxesSubplot:xlabel='DEPARTAMENTO'>
data['contar_fall'].hist()
<matplotlib.axes._subplots.AxesSubplot at 0x7f5357448290>
data['contar_pos'].hist()
<matplotlib.axes._subplots.AxesSubplot at 0x7f5356e6a610>
plt.figure(figsize=(15, 10))
sns.boxplot(y = 'contar_fall', x = 'Riesgo_distrito', data = data)
<matplotlib.axes._subplots.AxesSubplot at 0x7f5356dd2250>
plt.figure(figsize=(15, 10))
sns.boxplot(y = 'contar_pos', x = 'Riesgo_distrito', data = data)
<matplotlib.axes._subplots.AxesSubplot at 0x7f5356e64a50>