You probably read the documentation (as this example is from there) but somehow missed concept of 'label' i.e. row and column names (two first rows in documentation of pd.DataFrame.loc):.
These labels are positional, which means that you can skip columns:
Quote:Access a group of rows and columns by label(s) or a boolean array.
.loc[] is primarily label based, but may also be used with a boolean array.
These labels are positional, which means that you can skip columns:
In [18]: df.loc['viper'] # no column labels specified, all are selected implicitly Out[18]: max_speed 3 shield 4 Name: viper, dtype: int64 In [19]: df.loc['viper', :] # all column labels selected explicitly with : Out[19]: max_speed 3 shield 4 Name: viper, dtype: int64But not rows:
In [20]: df.loc[:, 'shield'] # all rows are explicitly selected Out[20]: cobra 2 viper 4 sidewinder 6 Name: shield, dtype: int64 In [21]: df.loc['shield'] # no row label 'shield' (first positional argument) /...../ KeyError: 'shield'
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.