Python位置索引的介绍

Python (186) 2023-05-05 19:15:23

说明

1、位置索引 ( df.iloc[...])需要确定切片的位置。

2、位置索引利用iloc传入行或者列的位置,逗号之前是行位置,逗号之后是列位置。索引位置从0开始,左开右闭。

实例

纯文本
复制到剪贴板
在新窗口中打开代码
EnlighterJS 3 Syntax Highlighter
mask=df['A']=='foo'
pos=np.flatnonzero(mask)
df.iloc[pos]
ABCD
0fooone00
2footwo24
4footwo48
6fooone612
7foothree714
mask=df['A']=='foo' pos=np.flatnonzero(mask) df.iloc[pos] ABCD 0fooone00 2footwo24 4footwo48 6fooone612 7foothree714
mask=df['A']=='foo'
pos=np.flatnonzero(mask)
df.iloc[pos]

ABCD
0fooone00
2footwo24
4footwo48
6fooone612
7foothree714

以上就是Python布尔索引的使用,希望对大家有所帮助。

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

THE END

发表回复