Accessing pandas DataFrames

Python for MATLAB Users

Justin Kiggins

Product Manager

Selecting multiple dataframe columns

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 for MATLAB Users

Selecting rows

  1. pandas indexing with .loc
  2. Python indexing with .iloc
Python for MATLAB Users

Selecting rows using pandas indexing

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 for MATLAB Users

Selecting rows using Python indexing

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 for MATLAB Users

Let's practice!

Python for MATLAB Users

Preparing Video For Download...