Why does .loc work with integer index positions?
问题 The pandas documentation of .loc clearly states: .loc is strictly label based, will raise KeyError when the items are not found, allowed inputs are: A single label, e.g. 5 or 'a', (note that 5 is interpreted as a label of the index. This use is not an integer position along the index) Contrary to that, this surprisingly works for pd.Series , not for pd.DataFrame: import numpy as np a = np.array([1,3,1,2]) import pandas as pd s = pd.Series(a, index=["a", "b", "c", "d"]) s.loc["a"] # yields 1 s