pandas以類似字典的方式來獲取某一列的值,比如df[‘A’],這會得到df的A列。如果我們對某一行感興趣呢?這個時候有兩種方法,一種是iloc方法,另一種方法是loc方法。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來索引,比如下邊的df定義了一個index,那么loc就根據這個index來索引對應的行。iloc並不是根據index來索引,而是根據行號來索引,行號從0開始,逐次加1。