Does loc in pandas use vectorised logic or a for loop?

南楼画角 提交于 2019-12-13 03:44:55

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!