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

se añaden graficas de analisis

parent 7bfd4af7
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` python
import pandas as pd
import csv
import numpy as np
import matplotlib as plt
import seaborn as sns
import math
```
%% Cell type:code id: tags:
``` python
df_species = pd.read_csv("~/ejercicios-clase-08-datos/data-used/species.csv")
df_surveys = pd.read_csv("~/ejercicios-clase-08-datos/data-used/surveys.csv")
```
%% Cell type:code id: tags:
``` python
pip install --upgrade pip
df_species.head()
```
%% Cell type:code id: tags:
%% Output
``` python
df_species.head()
```
species_id genus species taxa
0 AB Amphispiza bilineata Bird
1 AH Ammospermophilus harrisi Rodent
2 AS Ammodramus savannarum Bird
3 BA Baiomys taylori Rodent
4 CB Campylorhynchus brunneicapillus Bird
%% Cell type:code id: tags:
``` python
df_surveys.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:code id: tags:
``` python
df_surveys
```
%% 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
... ... ... ... ... ... ... ... ...
35544 35545 12 31 2002 15 AH NaN NaN
35545 35546 12 31 2002 15 AH NaN NaN
35546 35547 12 31 2002 10 RM F 15.0
35547 35548 12 31 2002 7 DO M 36.0
35548 35549 12 31 2002 5 NaN NaN NaN
weight
0 NaN
1 NaN
2 NaN
3 NaN
4 NaN
... ...
35544 NaN
35545 NaN
35546 14.0
35547 51.0
35548 NaN
[35549 rows x 9 columns]
%% Cell type:code id: tags:
``` python
df_species['species_id'].unique()
```
%% Output
array(['AB', 'AH', 'AS', 'BA', 'CB', 'CM', 'CQ', 'CS', 'CT', 'CU', 'CV',
'DM', 'DO', 'DS', 'DX', 'EO', 'GS', 'NL', 'NX', 'OL', 'OT', 'OX',
'PB', 'PC', 'PE', 'PF', 'PG', 'PH', 'PI', 'PL', 'PM', 'PP', 'PU',
'PX', 'RF', 'RM', 'RO', 'RX', 'SA', 'SB', 'SC', 'SF', 'SH', 'SO',
'SS', 'ST', 'SU', 'SX', 'UL', 'UP', 'UR', 'US', 'ZL', 'ZM'],
dtype=object)
%% Cell type:code id: tags:
``` python
df_surveys['species_id'].unique()
```
%% Output
array(['NL', 'DM', 'PF', 'PE', 'DS', 'PP', 'SH', 'OT', 'DO', 'OX', 'SS',
'OL', 'RM', nan, 'SA', 'PM', 'AH', 'DX', 'AB', 'CB', 'CM', 'CQ',
'RF', 'PC', 'PG', 'PH', 'PU', 'CV', 'UR', 'UP', 'ZL', 'UL', 'CS',
'SC', 'BA', 'SF', 'RO', 'AS', 'SO', 'PI', 'ST', 'CU', 'SU', 'RX',
'PB', 'PL', 'PX', 'CT', 'US'], dtype=object)
%% Cell type:code id: tags:
``` python
df_surveysspecie= pd.merge(df_surveys,df_species,how='left',on=['species_id'])
```
%% Cell type:code id: tags:
``` python
df_surveysspecie
```
%% Cell type:code id: tags:
%% Output
``` python
df_group_specie_id = df_surveysspecie.groupby('taxa').unique()
df_group_specie_id
```
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
... ... ... ... ... ... ... ... ...
35544 35545 12 31 2002 15 AH NaN NaN
35545 35546 12 31 2002 15 AH NaN NaN
35546 35547 12 31 2002 10 RM F 15.0
35547 35548 12 31 2002 7 DO M 36.0
35548 35549 12 31 2002 5 NaN NaN NaN
weight genus species taxa
0 NaN Neotoma albigula Rodent
1 NaN Neotoma albigula Rodent
2 NaN Dipodomys merriami Rodent
3 NaN Dipodomys merriami Rodent
4 NaN Dipodomys merriami Rodent
... ... ... ... ...
35544 NaN Ammospermophilus harrisi Rodent
35545 NaN Ammospermophilus harrisi Rodent
35546 14.0 Reithrodontomys megalotis Rodent
35547 51.0 Dipodomys ordii Rodent
35548 NaN NaN NaN NaN
[35549 rows x 12 columns]
%% Cell type:code id: tags:
``` python
plt.pyplot.scatter(df_surveysspecie[df_surveysspecie['weight']>0],df_surveysspecie[df_surveysspecie['hindfoot_length']>0]['weight'])
```
plt.pyplot.scatter(df_surveysspecie[df_surveysspecie['weight']>0][df_surveysspecie['hindfoot_length']>0][df_surveysspecie['hindfoot_length']<40][df_surveysspecie['taxa']=='Rodent']['weight'],
df_surveysspecie[df_surveysspecie['weight']>0][df_surveysspecie['hindfoot_length']>0][df_surveysspecie['hindfoot_length']<40][df_surveysspecie['taxa']=='Rodent']['hindfoot_length'])
```
%% Output
/home/student/.local/lib/python3.6/site-packages/ipykernel_launcher.py:1: UserWarning: Boolean Series key will be reindexed to match DataFrame index.
"""Entry point for launching an IPython kernel.
/home/student/.local/lib/python3.6/site-packages/ipykernel_launcher.py:2: UserWarning: Boolean Series key will be reindexed to match DataFrame index.
<matplotlib.collections.PathCollection at 0x7f12bcedf748>
%% Cell type:code id: tags:
``` python
plt.pyplot.scatter(df_surveysspecie[df_surveysspecie['taxa']=='Rodent'][df_surveysspecie['hindfoot_length']>0]['year'],df_surveysspecie[df_surveysspecie['taxa']=='Rodent'][df_surveysspecie['hindfoot_length']>0]['hindfoot_length'])
```
%% Cell type:code id: tags:
``` python
df_surveysspecie[df_surveysspecie['taxa']=='Rodent']['weight']
```
%% Cell type:code id: tags:
``` python
df_surveysspecie.info()
```
%% Cell type:code id: tags:
``` python
df_surveysspecie['hindfoot_length']=df_surveysspecie['hindfoot_length'].fillna(0)
```
%% Cell type:code id: tags:
``` python
df_surveysspecie['weight']=df_surveysspecie['weight'].fillna(0)
```
%% Cell type:code id: tags:
``` python
plt.pyplot.scatter(df_surveysspecie['taxa'](skipna=True),df_surveysspecie['weight'])
```
%% Cell type:code id: tags:
``` python
df_surveysspecie['taxa'].hist()
```
%% Cell type:code id: tags:
``` python
df_surveysspecie['taxa'].unique()
```
%% Cell type:code id: tags:
``` python
df_surveysspecie[df_surveysspecie['weight']>0]['weight'].max()
```
%% Cell type:code id: tags:
``` python
df_weight_vs_taxa= pd.concat([df_surveysspecie[df_surveysspecie['weight']>0]['weight'],df_surveysspecie[df_surveysspecie['weight']>0]['taxa']],axis=1)
f,ax=plt.subplots()
fig
df_weight_vs_taxa= pd.concat([df_surveysspecie[df_surveysspecie['weight']>0][df_surveysspecie['hindfoot_length']>40]['hindfoot_length'],
df_surveysspecie[df_surveysspecie['weight']>0][df_surveysspecie['hindfoot_length']>40]['month'],
df_surveysspecie[df_surveysspecie['weight']>0][df_surveysspecie['hindfoot_length']>40]['sex']],axis=1)
f,ax=plt.pyplot.subplots(figsize=(14,6))
fig = sns.boxplot(x='month',y='hindfoot_length',hue='sex',data=df_weight_vs_taxa)
plt.pyplot.xticks(rotation=90)
```
%% Output
/home/student/.local/lib/python3.6/site-packages/ipykernel_launcher.py:1: UserWarning: Boolean Series key will be reindexed to match DataFrame index.
"""Entry point for launching an IPython kernel.
/home/student/.local/lib/python3.6/site-packages/ipykernel_launcher.py:2: UserWarning: Boolean Series key will be reindexed to match DataFrame index.
/home/student/.local/lib/python3.6/site-packages/ipykernel_launcher.py:3: UserWarning: Boolean Series key will be reindexed to match DataFrame index.
This is separate from the ipykernel package so we can avoid doing imports until
(array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]),
<a list of 12 Text xticklabel objects>)
%% Cell type:code id: tags:
``` python
df_promyear = df_surveysspecie.groupby(['year','sex']).mean()
df_promyear.head()
```
%% Output
record_id month day plot_id hindfoot_length \
year sex
1977 F 242.343137 9.480392 15.171569 11.387255 36.574359
M 228.350467 9.313084 15.364486 11.747664 36.165877
1978 F 1059.359841 6.910537 8.143141 10.781312 38.303493
M 1019.023095 6.498845 8.330254 10.501155 36.145729
1979 F 1915.168196 6.688073 22.874618 11.798165 34.871287
weight
year sex
1977 F 47.607692
M 46.135338
1978 F 69.959052
M 65.348371
1979 F 65.562500
%% Cell type:code id: tags:
``` python
sns.scatterplot(x='year',y='hindfoot_length',hue='sex',data=df_promyear)
```
%% Output
<matplotlib.axes._subplots.AxesSubplot at 0x7f12bb2b38d0>
%% Cell type:code id: tags:
``` python
```
......
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