To get a scalar at integer location 0
and column label 'A'
in a data frame df
, I do chained indexing: df.iloc[0]['A']
. This works, but pandas documentation says that chained indexing should be avoided.
An alternative I could come up with is df.iat[0, df.columns.get_loc('A')]
, which is just too much typing compared with the chained indexing. Is there a shorter way to do this?
Note: .ix indexer is deprecated.
Example:
df=pd.DataFrame({'A':[10,20,30,40]}, index=[3,2,1,0])
A ------ 3 10 2 20 1 30 0 40
The scalar at integer location 0
in column A
is 10
and not 40
:
df.iat[0, df.columns.get_loc('A')]
Otuput: 10