pandas 中的loc是否使用矢量化逻辑或for循环? [英] Does loc in pandas use vectorised logic or a for loop?
本文介绍了 pandas 中的loc是否使用矢量化逻辑或for循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用loc函数访问大熊猫中的行,如下所示:
I access rows in pandas with the loc function as below:
pdf.loc[pdf.a>2]
这是矢量化的吗?比使用numpy
Is this vectorised? Is it better than using numpy
pdf[pdf.a>2]
推荐答案
此时间表明loc并没有减慢速度
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
这篇关于 pandas 中的loc是否使用矢量化逻辑或for循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文