Skip to content
Snippets Groups Projects
Commit cb7a7fea authored by Arturo Sanchez's avatar Arturo Sanchez
Browse files

Entrega de proyecto

parent 32764260
Branches master
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` python
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
```
%% Cell type:markdown id: tags:
# Lectura de datos
%% Cell type:code id: tags:
``` python
df = pd.read_csv("surveys.csv")
df.head()
```
%% Output
record_id month day year plot_id species_id sex hindfoot_length \
0 1 7 16 1977 2 NL M 32.0
1 2 7 16 1977 3 NL M 33.0
2 3 7 16 1977 2 DM F 37.0
3 4 7 16 1977 7 DM M 36.0
4 5 7 16 1977 3 DM M 35.0
weight
0 NaN
1 NaN
2 NaN
3 NaN
4 NaN
%% Cell type:markdown id: tags:
# Analisis por columna del peso y la longitud del pie trasero
%% Cell type:code id: tags:
``` python
plt.figure()
plt.title('Histograma de la longitud de pie trasero')
plt.xlabel('Longitud del pie trasero')
df['hindfoot_length'].plot.hist(alpha=0.5,edgecolor='black')
plt.figure()
plt.title('Histograma del peso')
plt.xlabel('peso')
df['weight'].plot.hist(alpha=0.5,edgecolor='black')
```
%% Output
<AxesSubplot:title={'center':'Histograma del peso'}, xlabel='peso', ylabel='Frequency'>
%% Cell type:code id: tags:
``` python
#Estadistica de las propiedades de la longitud del pie trasero y el peso de todas las muestras
f=df.describe()[['hindfoot_length','weight']]
f.columns=['Longitud del pie trasero','peso']
f
```
%% Output
Longitud del pie trasero peso
count 31438.000000 32283.000000
mean 29.287932 42.672428
std 9.564759 36.631259
min 2.000000 4.000000
25% 21.000000 20.000000
50% 32.000000 37.000000
75% 36.000000 48.000000
max 70.000000 280.000000
%% Cell type:markdown id: tags:
# Funciones de utilidad
%% Cell type:code id: tags:
``` python
#Funcion que haya el valor medio de la longitud del pie y el paso, para una cierta caracteristica de la tabla con su desviacion
#estandar
def analisis(carac):
x=[]
y=[]
xerror=[]
yerror=[]
for i in df[carac].unique():
pie=df[df[carac]==i]["hindfoot_length"].mean()
piedesv=df[df[carac]==i]["hindfoot_length"].std()
peso=df[df[carac]==i]["weight"].mean()
pesodesv=df[df[carac]==i]["weight"].mean()
x.append(pie)
xerror.append(piedesv)
y.append(peso)
yerror.append(pesodesv)
return x,xerror,y,yerror
#x,xerror,y,yerror=analisis('day')
```
%% Cell type:code id: tags:
``` python
#Se encarga de pintar los datos
def graficas(carac):
x,xerror,y,yerror=analisis(carac)
plt.figure(figsize=(10,5))
plt.errorbar(np.array(list(df[carac].unique())),x,xerror,fmt='.k')
plt.ylabel('tamaño del pie trasero')
plt.xlabel(carac)
plt.grid()
plt.figure(figsize=(10,5))
plt.errorbar(np.array(list(df[carac].unique())),y,yerror,fmt='.k')
plt.ylabel('peso')
plt.xlabel(carac)
plt.grid()
```
%% Cell type:markdown id: tags:
# Analisis por sexo
%% Cell type:code id: tags:
``` python
#Comparacion de los sexos en los datos
#df["sex"].value_counts().plot(kind="bar")
df["sex"].value_counts().plot.pie(autopct="%.2f")
#plt.ylabel('frecuencia')
```
%% Output
<AxesSubplot:ylabel='sex'>
%% Cell type:code id: tags:
``` python
#Valores estadisticos de longitud del pie trasero para el sexo femenino y masculino
x=df[df["sex"]=='F']['hindfoot_length'].describe()
y=df[df["sex"]=='M']['hindfoot_length'].describe()
f=pd.concat([x, y],axis=1)
f.columns=['Longitud del pie trasero F','Longitud del pie trasero M']
f
```
%% Output
Longitud del pie trasero F Longitud del pie trasero M
count 14894.000000 16476.000000
mean 28.836780 29.709578
std 9.463789 9.629246
min 7.000000 2.000000
25% 21.000000 21.000000
50% 27.000000 34.000000
75% 36.000000 36.000000
max 64.000000 58.000000
%% Cell type:code id: tags:
``` python
#Valores estadisticos de peso trasero para el sexo femenino y masculino
x=df[df["sex"]=='F']['weight'].describe()
y=df[df["sex"]=='M']['weight'].describe()
f=pd.concat([x, y],axis=1)
f.columns=['Peso F','Peso M']
f
```
%% Output
Peso F Peso M
count 15303.000000 16879.000000
mean 42.170555 42.995379
std 36.847958 36.184981
min 4.000000 4.000000
25% 20.000000 20.000000
50% 34.000000 39.000000
75% 46.000000 49.000000
max 274.000000 280.000000
%% Cell type:markdown id: tags:
## Sexo masculino
%% Cell type:code id: tags:
``` python
#Correlacion lineal entre el peso y la longitud del pie trasero para el sexo masculino
df[df["sex"]=='M'][['hindfoot_length','weight']].corr()
```
%% Output
hindfoot_length weight
hindfoot_length 1.000000 0.701169
weight 0.701169 1.000000
%% Cell type:code id: tags:
``` python
# Histograma de las caracteriticas
df[df["sex"]=='M'][['hindfoot_length','weight']].hist(edgecolor='black')
```
%% Output
array([[<AxesSubplot:title={'center':'hindfoot_length'}>,
<AxesSubplot:title={'center':'weight'}>]], dtype=object)
%% Cell type:markdown id: tags:
## Sexo femenino
%% Cell type:code id: tags:
``` python
df[df["sex"]=='F'][['hindfoot_length','weight']].corr()
```
%% Output
hindfoot_length weight
hindfoot_length 1.000000 0.665526
weight 0.665526 1.000000
%% Cell type:code id: tags:
``` python
# Histograma de las caracteriticas
df[df["sex"]=='F'][['hindfoot_length','weight']].hist(edgecolor='black')
```
%% Output
array([[<AxesSubplot:title={'center':'hindfoot_length'}>,
<AxesSubplot:title={'center':'weight'}>]], dtype=object)
%% Cell type:markdown id: tags:
# Analisis en el tiempo
%% Cell type:markdown id: tags:
### Valor medio y desviacion estandar por dia del pie trasero y el peso
%% Cell type:code id: tags:
``` python
graficas('day')
```
%% Output
%% Cell type:markdown id: tags:
### Valor medio y desviacion estandar por **mes** del pie trasero y el peso
%% Cell type:code id: tags:
``` python
graficas('month')
```
%% Output
%% Cell type:markdown id: tags:
### Valor medio y desviacion estandar por año del pie trasero y el peso
%% Cell type:code id: tags:
``` python
graficas('year')
```
%% Output
%% Cell type:markdown id: tags:
### Correlaciones
%% Cell type:code id: tags:
``` python
df[['day','hindfoot_length']].corr()
```
%% Output
day hindfoot_length
day 1.000000 -0.001469
hindfoot_length -0.001469 1.000000
%% Cell type:code id: tags:
``` python
df[['month','hindfoot_length']].corr()
```
%% Output
month hindfoot_length
month 1.00000 -0.01371
hindfoot_length -0.01371 1.00000
%% Cell type:code id: tags:
``` python
df[['year','hindfoot_length']].corr()
```
%% Output
year hindfoot_length
year 1.000000 -0.287259
hindfoot_length -0.287259 1.000000
%% Cell type:code id: tags:
``` python
df[['year','weight']].corr()
```
%% Output
year weight
year 1.000000 -0.276595
weight -0.276595 1.000000
%% Cell type:code id: tags:
``` python
df[['day','weight']].corr()
```
%% Output
day weight
day 1.000000 -0.008636
weight -0.008636 1.000000
%% Cell type:code id: tags:
``` python
df[['month','weight']].corr()
```
%% Output
month weight
month 1.00000 -0.00297
weight -0.00297 1.00000
%% Cell type:markdown id: tags:
# Analisis por especie
%% Cell type:code id: tags:
``` python
# Frecuencia de cada una de las especies
plt.figure(figsize=(14,5))
df["species_id"].value_counts().plot(kind="bar")
plt.ylabel('frecuencia')
```
%% Cell type:code id: tags:
``` python
graficas('species_id')
```
%% Output
source diff could not be displayed: it is too large. Options to address this: view the blob.
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment