Why is df.loc['row', 'col'] the same as df['col'].loc['row']?

47 Views Asked by At

I can see theyre both referencing the same cell/value, but why does df['col'].loc[row] even work? I learned to use loc as df.loc[rowname,colname].

I saw it in a list comprehension:

fb['Direction'] = [1 if fb['PriceDiff'].loc[ei] > 0 else 0 for ei in fb.index ]

So why would you write:

fb['PriceDiff'].loc[ei] 

and not:

fb.loc[ei, 'PriceDiff']

Is there any reason/advantage?

Thanks!

0

There are 0 best solutions below