我在数据框中具有iloc索引,并希望获取相应的loc索引。换句话说:我想要一个函数ilocIndex_to_locIndex
将ilocIndex
转换为locIndex
df = pd.DataFrame({1 : [1,2,3,4], 2 : [5,6,7,8]})
df = df.drop([1])
iatIndex = 2
df.iloc[ilocIndex]
locIndex = df.ilocIndex_to_locIndex(ilocIndex)
df.loc[locIndex]
答案 0 :(得分:3)
您可以为.index
下标:
>>> df.index[2]
3