Python Pandas - 如何按整数位置从 DataFrame 中选择行
要按整数位置选择行,请使用该iloc()函数。提及要选择的行的索引号。
创建一个数据帧-
dataFrame = pd.DataFrame([[10, 15], [20, 25], [30, 35]],index=['x', 'y', 'z'],columns=['a', 'b'])
使用整数位置选择行iloc()-
dataFrame.iloc[1]
示例
以下是代码-
import pandas as pd #CreateDataFrame dataFrame = pd.DataFrame([[10, 15], [20, 25], [30, 35]],index=['x', 'y', 'z'],columns=['a', 'b']) #DataFrame print"DataFrame...\n",dataFrame #selectrowswithloc print"\nSelect rows by passing label..." print(dataFrame.loc['z']) #selectrowswithintegerlocationusingiloc print"\nSelect rows by passing integer location..." print(dataFrame.iloc[1])输出结果
这将产生以下输出-
DataFrame...
a b
x 10 15
y 20 25
z 30 35
Select rows by passing label...
a 30
b 35
Name: z, dtype: int64
Select rows by passing integer location...
a 20
b 25
Name: y, dtype: int64热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便