Skip to content Skip to sidebar Skip to footer

Does Loc In Pandas Use Vectorised Logic Or A For Loop?

I access rows in pandas with the loc function as below: pdf.loc[pdf.a>2] Is this vectorised? Is it better than using numpy pdf[pdf.a>2]

Solution 1:

This timing suggests there is no slow down with loc

testa = pd.DataFrame(np.arange(10000000),columns =['q'])
%timeittestb= testa.loc[testa.q>6] 
%timeittestc= testa[testa.q>7]

1loop, best of 3: 207 ms per loop1loop, best of 3: 208 ms per loop

Post a Comment for "Does Loc In Pandas Use Vectorised Logic Or A For Loop?"