Pandas庫中iloc[]函數(shù)的使用方法
1 iloc[]函數(shù)作用
iloc[]函數(shù),屬于pandas庫,全稱為index location,即對(duì)數(shù)據(jù)進(jìn)行位置索引,從而在數(shù)據(jù)表中提取出相應(yīng)的數(shù)據(jù)。
2 iloc函數(shù)使用
df.iloc[a,b],其中df是DataFrame數(shù)據(jù)結(jié)構(gòu)的數(shù)據(jù)(表1就是df),a是行索引(見表1),b是列索引(見表1)。
| 姓名(列索引10) | 班級(jí)(列索引1) | 分?jǐn)?shù)(列索引2) | |
| 0(行索引0) | 小明 | 302 | 87 |
| 1(行索引1) | 小王 | 303 | 95 |
| 2(行索引2) | 小方 | 303 | 100 |
1.iloc[a,b]:取行索引為a列索引為b的數(shù)據(jù)。
import pandas
df = pandas.read_csv('a.csv')
print(df.iloc[1,2])
#Out:952.iloc[a:b,c]:取行索引從a到b-1,列索引為c的數(shù)據(jù)。注意:在iloc中a:b是左到右不到的,即lioc[1:3,:]是從行索引從1到2,所有列索引的數(shù)據(jù)。
import pandas
df = pandas.read_csv('a.csv')
print(df.iloc[0:2,2]) #數(shù)據(jù)結(jié)構(gòu)是Series
print(df.iloc[0:2,2].values) #數(shù)據(jù)結(jié)構(gòu)是ndarray
#Out1:0 87
# 1 95
# Name: 分?jǐn)?shù), dtype: int64
#Out2:[87 95]iloc[].values,用values屬性取值,返回ndarray,但是單個(gè)數(shù)值無法用values函數(shù)讀取。
3.iloc[a:b,c:d]:取行索引從a到b-1,列索引從c到d-1的數(shù)據(jù)。
import pandas
df = pandas.read_csv('a.csv')
print(df.iloc[0:2,0:2])
print(df.iloc[0:2,0:2].values)
#Out1: 姓名 班級(jí)
# 0 小明 302
# 1 小王 303
#Out2:[['小明' 302]
# ['小王' 303]]4.iloc[a]:取取行索引為a,所有列索引的數(shù)據(jù)。
import pandas
df = pandas.read_csv('a.csv')
print(df.iloc[2])
print(df.iloc[2].values)
#Out1:姓名 小方
# 班級(jí) 303
# 分?jǐn)?shù) 100
# Name: 2, dtype: object
#Out2:['小方' 303 100]總結(jié)
到此這篇關(guān)于Pandas庫中iloc[]函數(shù)使用的文章就介紹到這了,更多相關(guān)Pandas庫iloc[]函數(shù)使用內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Python pandas中的iloc使用小結(jié)
- Pandas中的loc與iloc區(qū)別與用法小結(jié)
- pandas loc與iloc用法及區(qū)別
- python中pandas庫的iloc函數(shù)用法解析
- 一文秒懂pandas中iloc()函數(shù)
- pandas loc iloc ix用法詳細(xì)分析
- 利用Pandas讀取某列某行數(shù)據(jù)之loc和iloc用法總結(jié)
- Python Pandas數(shù)據(jù)分析之iloc和loc的用法詳解
- python pandas中索引函數(shù)loc和iloc的區(qū)別分析
- pandas中.loc和.iloc以及.at和.iat的區(qū)別說明
- pandas中iloc函數(shù)的具體實(shí)現(xiàn)
相關(guān)文章
python中not not x 與bool(x) 的區(qū)別
這篇文章主要介紹了python中not not x 與 bool(x) 的區(qū)別,我們就來做一個(gè)選擇,就是 not not x 和 bool(x) 用哪個(gè)比較好?下面一起進(jìn)入文章看看吧2021-12-12
python中對(duì)數(shù)據(jù)進(jìn)行各種排序的方法
這篇文章主要介紹了python中對(duì)數(shù)據(jù)進(jìn)行各種排序的方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下2019-07-07
使用flask如何獲取post請(qǐng)求參數(shù)
近日在使用flask框架獲取前端的請(qǐng)求時(shí)獲取參數(shù)時(shí),遇到了幾個(gè)問題,所以下面這篇文章主要給大家介紹了關(guān)于使用flask如何獲取post請(qǐng)求參數(shù)的相關(guān)資料,需要的朋友可以參考下2022-08-08
Python sqlite3事務(wù)處理方法實(shí)例分析
這篇文章主要介紹了Python sqlite3事務(wù)處理方法,結(jié)合具體實(shí)例形式分析了Python針對(duì)sqlite3事務(wù)處理的操作技巧,代碼中包含詳盡的注釋,需要的朋友可以參考下2017-06-06
Pytorch如何打印與Keras的model.summary()類似的輸出(最新推薦)
這篇文章主要介紹了Pytorch如何打印與Keras的model.summary()類似的輸出,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-07-07

