Mengakses DataFrame pandas

Python untuk Pengguna MATLAB

Justin Kiggins

Product Manager

Memilih beberapa kolom 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 untuk Pengguna MATLAB

Memilih baris

  1. Pengindeksan pandas dengan .loc
  2. Pengindeksan Python dengan .iloc
Python untuk Pengguna MATLAB

Memilih baris dengan pengindeksan 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 untuk Pengguna MATLAB

Memilih baris dengan pengindeksan 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 untuk Pengguna MATLAB

Ayo berlatih!

Python untuk Pengguna MATLAB

Preparing Video For Download...