Dataframe iterating question : 3 ways of calling a row and column

zach.smith at orthofi.com zach.smith at orthofi.com
Mon Aug 21 13:08:26 EDT 2017


I wouldn't say I'm a Python noob, but I wouldn't say I'm a Python expert either. I work in data science and use Pandas Dataframes a lot. My question is regarding the difference in calling out a specific row, column combination in a dataframe.

I see 3 ways of doing this:
(1) df.loc[row_ind, column_ind]
(2) df.column_ind.loc[row_ind]
(3) df[column_ind].loc[row_ind]

where column_ind is the column name & row_ind is the named row index/row name in the dataframe.

Can anyone enlighten me as to the differences between the above 3 methods of getting to the same cell in the dataframe? 
Are there speed differences? 
Is it simply a preference thing? 
Is there a PEP8 preferred way of doing this?
Are there specific disadvantages to any of the methods?

Thanks in advance.
Zach



More information about the Python-list mailing list