问题
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]
回答1:
This timing suggests there is no slow down with loc
testa = pd.DataFrame(np.arange(10000000),columns =['q'])
%timeit testb = testa.loc[testa.q>6]
%timeit testc = testa[testa.q>7]
1 loop, best of 3: 207 ms per loop
1 loop, best of 3: 208 ms per loop
来源:https://stackoverflow.com/questions/55874138/does-loc-in-pandas-use-vectorised-logic-or-a-for-loop