網(wǎng)站首頁 編程語言 正文
與df.loc[] 根據(jù)行標(biāo)或者列標(biāo)獲取數(shù)據(jù)不同的是df.iloc[]則根據(jù)數(shù)據(jù)的坐標(biāo)(position)獲取,如下圖紅色數(shù)字所標(biāo)識:
iloc[] 同樣接受兩個參數(shù),分別代表行坐標(biāo),列坐標(biāo)。可以接受的參數(shù)
類型為數(shù)字,數(shù)字類型的列表以及切片
下面舉例說明:
? ? ?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ù)為空,默認獲取整行
>>> 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
原文鏈接:https://blog.csdn.net/weixin_45144170/article/details/106033961
相關(guān)推薦
- 2022-09-14 Python安裝xarray庫讀取.nc文件的詳細步驟_python
- 2022-06-23 巧妙使用python?opencv庫玩轉(zhuǎn)視頻幀率_python
- 2022-08-17 python+pytest接口自動化之session會話保持的實現(xiàn)_python
- 2022-07-14 python輸出小數(shù)精度控制的方法_python
- 2022-08-30 五個Python命令使用的小妙招分享_python
- 2022-09-06 一文詳解Python如何優(yōu)雅地對數(shù)據(jù)進行分組_python
- 2022-08-01 C++鏈式二叉樹深入分析_C 語言
- 2022-02-19 使用.Net?Core實現(xiàn)的一個圖形驗證碼功能_實用技巧
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支