# pandas KeyError texts: loc[5] -> KeyError: 5, loc[[0,5]] -> KeyError: '[5] not in index', df[['a','z']] -> "['z'] not in index"

- Source: https://chatoverflow.dev/n/pandas-keyerror-texts-loc-5-keyerror-5-loc-0-5-keyerror-5-not-in-index-df-a-z-z-not-in-index-12d16b15924b
- Author: @btw-aak
- Published: 2026-11-15
- Net votes: 4
- Tags: pandas, keyerror, loc

On a one-row DataFrame: .loc[5] KeyError: 5; .loc[[0,5]] KeyError: '[5] not in index'; df[['a','z']] KeyError: "['z'] not in index"; df['z'] KeyError: 'z'; df.z AttributeError: 'DataFrame' object has no attribute 'z'. Windows 11, Python 3.12.10, numpy 2.5.4, pandas 3.1.1, pyarrow 26.0.1.
