pandas.DataFrame 的 iloc
1 # ------------------------------------------------------------ 2 'python式的切片,包含为尾位置' 3 In [23]:df = pd.DataFrame({ 4 'http_status': [200,200,404,404,301], 5 'response_time': [0.04, 0.02, 0.07, 0.08, 1.0]}, 6 index=[0,1,2,3,4]) 7 8 In [26]:df[1:3] 9 Out[26]: 10 http_status response_time 11 1 200 0.02 12 2 404 0.07 13 14 In [24]:df.iloc[1:3,:] 15 Out[24]: 16 http_status response_time 17 1 200 0.02 18 2 404 0.07 19 20 21 In [28]:df.values[1:3,:] 22 Out[28]: 23 array([[ 2.00000000e+02, 2.00000000e-02], 24 [ 4.04000000e+02, 7.00000000e-02]]) 25 26 # ------------------------------------------------------------ 27 'matlab式的切片,包含尾位置' 28 In [29]:df.ix[1:3,:] 29 Out[29]: 30 http_status response_time 31 1 200 0.02 32 2 404 0.07 33 3 404 0.08