我有一个数据帧是从另一个数据帧中采样的,因此它的行顺序不会一一递增:
col1 col2
14 info1 info2
25 info3 info3
46 info5 info6
还有一个索引对象:
Int64Index([ 273, 447, 1073, 1079, 1416, 1757, 1786, 2072,
2389, 2657,
...
366433, 366457, 366472, 367458, 367971, 368195, 368505, 369282,
369402, 371835],
dtype='int64', length=737)
我需要根据数据帧中的索引对象选择行,但是,.loc
似乎没有按预期工作,因为当我使用df.iloc[Int64Index]
时,界错误。而且,如果我仅从索引对象中选择一个整数(例如273),则会发现选择的是数据框中的第273行,而不是顺序为273的行。
答案 0 :(得分:1)
看起来索引中有空格。您可以这样做:
df.loc[' 273']