当存在LOC且存在数据时,df.iloc返回空

2024-09-30 00:23:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过使用基于索引的行位置简单地获得df的子集。但是,出于某些原因,以下代码有时返回空数据帧:

idx1 = 12105 # Get first index of interest
idxn = 12120  # Get last index of interest

print('idx1:',idx1)
print('idxn:',idxn)

rep = dist.iloc[idx1:idxn] # Get data between indexes of interest
print(rep)

“dist”数据帧(“Frame”是索引):

dist =
Frame   dist
12094   8.523
12095   9.776
12096  11.028
12097  12.105
12098  13.239
12099  14.354
12100  15.510
12101  16.620
12102  17.690
12103  18.777
12104  19.838
12105  20.795
12106  21.783
12107  22.878
12108  23.782
12109  24.686
12110  25.595
12111  26.485
12112  27.254
12113  28.067
12114  28.816
12115  29.558
12116  30.316
12117  30.925
12118  31.497
12119  32.100
12120  32.791
12121  33.308
12122  33.841
12123  34.440

输出:

idx1: 12105
idxn: 12120
Empty DataFrame
Columns: [dist]
Index: []

我一辈子都不明白为什么会发生这种事


Tags: of数据代码dfgetindexdist原因

热门问题