Pandas .at throwing ValueError: At based indexing on an integer index can only have integer indexers
Using at
with a boolean mask is considered bad form unless you can 100% guarantee only one row in the mask is true (otherwise, at
fails).
The best thing to do is to use loc
and take the first result.
df.loc[df.foo == 222, 'bar'].values[0]
555
For reference, at
does not work because returns a single-row Series with a index [2]
:
df[df.foo == 222].loc[:,'bar']
2 555
Name: bar, dtype: int64
At this point, at['bar']
makes no sense because it searches for "bar" in the index and bar
isn't. What you should've done is
df[df.foo == 222].at[2, 'bar']
555