當(dāng)前位置:
首頁(yè) >
Pandas——loc、iloc、ix 函数区别
發(fā)布時(shí)間:2025/3/19
35
豆豆
生活随笔
收集整理的這篇文章主要介紹了
Pandas——loc、iloc、ix 函数区别
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1、loc函數(shù)
通過(guò)行標(biāo)簽索引行數(shù)據(jù)。
可以多行,可以[行標(biāo)簽, 列標(biāo)簽]
輸出結(jié)果
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函數(shù)
通過(guò)行號(hào)索引行數(shù)據(jù)。
# iloc——通過(guò)行號(hào)獲取行數(shù)據(jù) print(df2.iloc[1]) # print(df2.iloc['a']) # 通過(guò)行標(biāo)簽索引會(huì)報(bào)錯(cuò) print(df2.iloc[0:]) ## 多行 print(df2.iloc[:,[1]]) ## 列數(shù)據(jù)輸出結(jié)果
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函數(shù)
結(jié)合前兩種的混合索引
# ix——結(jié)合前兩種的混合索引 print(df2.ix[1]) print(df2.ix['e'])輸出結(jié)果
a 4 b 5 c 6 Name: e, dtype: int64 a 4 b 5 c 6 Name: e, dtype: int64總結(jié)
以上是生活随笔為你收集整理的Pandas——loc、iloc、ix 函数区别的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 用Scikit-learn和Tensor
- 下一篇: 用Scikit-learn和Tensor