Accedere ai DataFrame di pandas

Python per utenti MATLAB

Justin Kiggins

Product Manager

Selezionare più colonne del dataframe

pets[['frac_dog_owners','rank']]
                      frac_dog_owners  rank
state                                      
Alabama                         0.441    17
Arizona                         0.401    18
Arkansas                        0.479     6
California                      0.328    40
...
Virginia                        0.354    37
Washington                      0.363     5
West Virginia                   0.458     7
Wisconsin                       0.339    21
Wyoming                         0.388     9
Python per utenti MATLAB

Selezionare righe

  1. Indicizzazione pandas con .loc
  2. Indicizzazione Python con .iloc
Python per utenti MATLAB

Selezionare righe con l'indicizzazione pandas

pets.loc['Massachusetts']
rank                    47.000
num_households     2618000.000
frac_dog_owners          0.236
frac_cat_owners          0.341
Name: Massachusetts, dtype: float64
Python per utenti MATLAB

Selezionare righe con l'indicizzazione Python

pets.iloc[17]
rank                    4.000
num_households     548000.000
frac_dog_owners         0.346
frac_cat_owners         0.464
Name: Maine, dtype: float64
Python per utenti MATLAB

Facciamo pratica!

Python per utenti MATLAB

Preparing Video For Download...