python pandas:在iat / iloc和at / loc索引之间进行转换/转换

时间:2019-08-29 10:16:42

标签: python pandas

我在数据框中具有iloc索引,并希望获取相应的loc索引。换句话说:我想要一个函数ilocIndex_to_locIndexilocIndex转换为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]

1 个答案:

答案 0 :(得分:3)

您可以为.index下标:

>>> df.index[2]
3