考虑玩具数据帧 df1 和 df2,其中 df2 是 df1 的子集(不包括第一行)。
将 pandas 导入为 pd 将 numpy 导入为 np
df1 = pd.DataFrame({'colA':[3.0,9,45,7],'colB':['A','B','C','D']})
df2 = df1[1:]
现在让我们为每一帧找到 colA 的 argmax
np.argmax(df1.colA) ## result is "2", which is what I expected
np.argmax(df2.colA) ## result is still "2", which is not what I expected. I expected "1"
如果我的兴趣矩阵是 df2,我该如何解决这个索引问题?这个怪癖是与 pandas、numpy 还是只是 python 内存有关?