欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解pandas df.iloc[]的典型用法

 更新時(shí)間:2022年08月16日 09:43:02   作者:python小工具  
本文主要介紹了詳解pandas df.iloc[]的典型用法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

與df.loc[] 根據(jù)行標(biāo)或者列標(biāo)獲取數(shù)據(jù)不同的是df.iloc[]則根據(jù)數(shù)據(jù)的坐標(biāo)(position)獲取,如下圖紅色數(shù)字所標(biāo)識(shí):

iloc[] 同樣接受兩個(gè)參數(shù),分別代表行坐標(biāo),列坐標(biāo)。可以接受的參數(shù)

類型為數(shù)字,數(shù)字類型的列表以及切片

下面舉例說(shuō)明:

? ? ?name ?score grade
id ? ? ? ? ? ? ? ? ? ?
a ? ? bog ? ? 45 ? ? A
c ? jiken ? ? 67 ? ? B
d ? ? bob ? ? 23 ? ? A
b ? jiken ? ? 34 ? ? B
f ? ?lucy ? ? 98 ? ? A
e ? ?tidy ? ? 75 ? ? B

# 獲取坐標(biāo)為(0, 0)的數(shù)據(jù)
>>> df.iloc[0, 0]
'bog'

# 獲取0行所有數(shù)據(jù),列坐標(biāo)參數(shù)為空,默認(rèn)獲取整行
>>> df.iloc[0]
name ? ? bog
score ? ? 45
grade ? ? ?A
Name: a, dtype: object

# 獲取指定行列的數(shù)據(jù)
>>> df.iloc[[0,1], [0, 1]]
? ? ?name ?score
id ? ? ? ? ? ? ?
a ? ? bog ? ? 45
c ? jiken ? ? 67

# 將所有行列倒序排列
>>> df.iloc[::-1, ::-1]
? ?grade ?score ? name
id ? ? ? ? ? ? ? ? ? ?
e ? ? ?B ? ? 75 ? tidy
f ? ? ?A ? ? 98 ? lucy
b ? ? ?B ? ? 34 ?jiken
d ? ? ?A ? ? 23 ? ?bob
c ? ? ?B ? ? 67 ?jiken
a ? ? ?A ? ? 45 ? ?bog

到此這篇關(guān)于詳解pandas df.iloc[]的典型用法的文章就介紹到這了,更多相關(guān)pandas df.iloc[]用法  內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論