Python选取数据 iloc()函数和loc()函数区别

1.iloc()

iloc works on the positions in the index (so it only takes integers).
使用 数字索引数据 ,只能是数字(俗称index的序值)

In [1]: df = DataFrame(randn(5,2),index=range(0,10,2),columns=list('AB'))
df
          A         B
0  1.068932 -0.794307
2 -0.470056  1.192211
4 -0.284561  0.756029
6  1.037563 -0.267820
8 -0.538478 -0.800654
----------------------------------
df.iloc[[2]]#第2行
          A         B
4 -0.284561  0.756029

2.loc()

loc works on labels in the index
只能用 字符型标签索引数据 (dataframe的行标签或者列标签为数字 除外)(俗称index的具体值)

df.loc[[2]]#index值为2的行
          A         B
2 -0.470056  1.192211

你可能感兴趣的:(数据处理,python,数据提取,iloc,loc)