結論: 在pandas中,非unique的index無法通過df.loc[index]來達到多行選擇的目的。
以下面的數據為例:
month | count |
1 | 1 |
1 | 2 |
2 | 3 |
2 | 4 |
假如我們之前對dataframe做了dataframe.set_index('month', inplace=True)操作,將month轉換為index。
則無法通過dataframe.loc[1, 'count']來獲取month == 1的子數據, 代碼可能會報錯keyError或者 xxx is not unique。
即:對於含有非unique的index的dataframe,無法通過label name去定位多行數據。