pandas中的loc和iloc

loc是指location的意思,iloc中的i是指integer。这两者的区别如下:

loc works on labels in the index.
iloc works on the positions in the index (so it only takes integers)

也就是说loc是根据index来索引,

如果table定义了一个index,那么loc就根据这个index来索引对应的行。

而iloc是根据行号来索引,行号从0开始,逐次加1,比如table.iloc[0]就是索引第一行。
此外,当ioc后面有两个值时,则第一个值代表行号,第二个值代表列号。
table.iloc[0,1]就是索引第1行第2列。
此外,也可以用[:,1]的方式来获取第二列的所有行。

发布了7 篇原创文章 · 获赞 0 · 访问量 1036

猜你喜欢

转载自blog.csdn.net/qq_42362240/article/details/102530316
今日推荐