访问 pandas DataFrame

面向 MATLAB 用户的 Python

Justin Kiggins

Product Manager

选择多个 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
面向 MATLAB 用户的 Python

选择行

  1. 使用 pandas 的 .loc 索引
  2. 使用 Python 的 .iloc 索引
面向 MATLAB 用户的 Python

使用 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
面向 MATLAB 用户的 Python

使用 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
面向 MATLAB 用户的 Python

练习吧!

面向 MATLAB 用户的 Python

Preparing Video For Download...