pandas 定位 loc,iloc,ix

In [114]: df
Out[114]:
                   A         B         C         D
2018-06-30  0.318501  0.613145  0.485612  0.918663
2018-07-31  0.614796  0.711491  0.503203  0.170298
2018-08-31  0.530939  0.173830  0.264867  0.181273
2018-09-30  0.009428  0.622133  0.933908  0.813617
2018-10-31  0.126368  0.981736  0.358643  0.904409
2018-11-30  0.747830  0.294678  0.427755  0.803732
2018-12-31  0.549106  0.225865  0.530107  0.590769
2019-01-31  0.371511  0.191638  0.267706  0.279762

In [115]: df.ix[[2,5],['B','C']]
Out[115]:
                   B         C
2018-08-31  0.173830  0.264867
2018-11-30  0.294678  0.427755

loc:通过行标签索引数据

 

In [116]: df.loc['2018-06-30']
Out[116]:
A    0.318501
B    0.613145
C    0.485612
D    0.918663
Name: 2018-06-30 00:00:00, dtype: float64

iloc:通过行号索引行数据

In [118]: df.iloc[0]
Out[118]:
A    0.318501
B    0.613145
C    0.485612
D    0.918663
Name: 2018-06-30 00:00:00, dtype: float64

  

ix:通过行标签或行号索引数据(基于loc和iloc的混合)

posted @ 2018-06-04 18:06  酸奶加绿茶  阅读(666)  评论(0编辑  收藏  举报