pandas much slower than numpy?

前端 未结 1 1060
长发绾君心
长发绾君心 2021-01-18 05:01

The code below suggests that pandas may be much slower than numpy, at least in the specifi case of the function clip(). What is surprising is that making a roundtrip from pa

相关标签:
1条回答
  • 2021-01-18 05:48

    In master/0.13 (release very shortly), this is much faster (still slightly slower that native numpy because of handling of alignment/dtype/nans).

    In 0.12 it was applying per column, so this was a relatively expensive operation.

    In [4]: arr = np.random.randn(1000, 1000)
    
    In [5]: df=pd.DataFrame(arr)
    
    In [6]: %timeit np.clip(arr, 0, None)
    100 loops, best of 3: 6.62 ms per loop
    
    In [7]: %timeit df.clip_lower(0)
    100 loops, best of 3: 12.9 ms per loop
    
    0 讨论(0)
提交回复
热议问题