Pandas——loc、iloc、ix 函数区别
生活随笔
收集整理的這篇文章主要介紹了
Pandas——loc、iloc、ix 函数区别
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、loc函數
通過行標簽索引行數據。
可以多行,可以[行標簽, 列標簽]
輸出結果
a 4 b 5 c 6 Name: 11, dtype: int64 a 1 b 2 c 3 Name: d, dtype: int64a b c d 1 2 3 e 4 5 6 b 2 c 3 Name: d, dtype: int64c d 3 e 62、iloc函數
通過行號索引行數據。
# iloc——通過行號獲取行數據 print(df2.iloc[1]) # print(df2.iloc['a']) # 通過行標簽索引會報錯 print(df2.iloc[0:]) ## 多行 print(df2.iloc[:,[1]]) ## 列數據輸出結果
a 4 b 5 c 6 Name: e, dtype: int64a b c d 1 2 3 e 4 5 6b d 2 e 53、ix函數
結合前兩種的混合索引
# ix——結合前兩種的混合索引 print(df2.ix[1]) print(df2.ix['e'])輸出結果
a 4 b 5 c 6 Name: e, dtype: int64 a 4 b 5 c 6 Name: e, dtype: int64總結
以上是生活随笔為你收集整理的Pandas——loc、iloc、ix 函数区别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用Scikit-learn和Tensor
- 下一篇: 用Scikit-learn和Tensor