pandas 按位置选择
示例
的iloc(短为整数位置)方法允许选择基于它们的位置索引一个数据帧的行。这样,就可以像使用Python的列表切片那样对数据帧进行切片。
df = pd.DataFrame([[11, 22], [33, 44], [55, 66]], index=list("abc"))
df
# Out:
# 0 1
# a 11 22
# b 33 44
# c 55 66
df.iloc[0] # the 0th index (row)
# Out:
# 0 11
# 1 22
# Name: a, dtype: int64
df.iloc[1] # the 1st index (row)
# Out:
# 0 33
# 1 44
# Name: b, dtype: int64
df.iloc[:2] # the first 2 rows
# 0 1
# a 11 22
# b 33 44
df[::-1] # reverse order of rows
# 0 1
# c 55 66
# b 33 44
# a 11 22行位置可以与列位置组合
df.iloc[:, 1] # the 1st column # Out[15]: # a 22 # b 44 # c 66 # Name: 1, dtype: int64
另请参阅:按位置选择
热门推荐
10 生日摆摊祝福语简短独特
11 女士简短祝福语大全集
12 生日祝福语简短女友英语
13 朋友出国旅游祝福语简短
14 牛年的吉祥祝福语简短
15 中考祝福语 简短 签状
16 新年到来的祝福语简短
17 祝福语精选简短正能量
18 元旦英文祝福语大全简短