>>> pd.DataFrame([1], index=[\'1\']).loc[\'2\'] # KeyError >>> pd.DataFrame([1], index=[\'1\']).loc[[\'2\']] # KeyError >>> pd.DataFrame
I found an alternative (provided a check for df.empty is made beforehand). You could do something like this
df[df.index=='2'] -> returns either a dataframe with matched values or empty dataframe.