Are for-loops in pandas really bad? When should I care?

前端 未结 2 1494
情深已故
情深已故 2020-11-21 23:00

Are for loops really \"bad\"? If not, in what situation(s) would they be better than using a more conventional \"vectorized\" approach?1

2条回答
  •  时光取名叫无心
    2020-11-21 23:18

    In short

    • for loop + iterrows is extremely slow. Overhead isn't significant on ~1k rows, but noticeable on 10k+ rows.
    • for loop + itertuples is much faster than iterrows or apply.
    • vectorization is usually much faster than itertuples

    Benchmark

提交回复
热议问题