/* Route-Critical (index, V6 §3.6.3 — erzeugt von tools/generate_critical_css.mjs) */ .mydraft-svg-icon{display:inline-block;vertical-align:middle;color:currentcolor;flex-shrink:0;transition:color var(--duration-fast, 150ms) ease,stroke var(--duration-fast, 150ms) ease,fill var(--duration-fast, 150ms) ease}.mydraft-svg-icon circle,.mydraft-svg-icon line,.mydraft-svg-icon path,.mydraft-svg-icon polygon,.mydraft-svg-icon polyline,.mydraft-svg-icon rect{transition:stroke var(--duration-fast, 150ms) ease,fill var(--duration-fast, 150ms) ease}@layer components{.live-pulse-dot{width:8px;height:8px}}@layer overrides{.live-pulse-dot{width:8px;height:8px;background-color:var(--threat-critical,#ef4444);border-radius:50%;display:inline-block;box-shadow:rgba(239,68,68,.7) 0 0 0 0}}@media (prefers-reduced-motion:reduce){@layer overrides{#news-popup,#news-toast-banner,.animate-pulse,.live-pulse-dot,.live-pulsing-dot,.news-item-card{animation:auto ease 0s 1 normal none running none;transition:none}}} 🔒 Stop Using .iterrows(). Here's What Actually Fast Looks Like | Sichere Programmierung – TSECURITY.DE Zum Hauptinhalt springen
•
Windows Tipps & SecurityXbox is hiring a "Physical Games Strategist" — will Helix have discs?(18.10.2026 um 12:27 Uhr)
•
Linux Tipps & HardeningDistribution Release: CobaltX 0.3(18.10.2026 um 12:52 Uhr)
•••••••••
Windows Tipps & SecurityXbox is hiring a "Physical Games Strategist" — will Helix have discs?(18.10.2026 um 12:27 Uhr)
•
Linux Tipps & HardeningDistribution Release: CobaltX 0.3(18.10.2026 um 12:52 Uhr)
••••••••
Intelligence View
⚡ tsecurity.de Intelligence

Stop Using .iterrows(). Here's What Actually Fast Looks Like

You're looping over a DataFrame. It feels natural. It's killing your performance. # What most tutorials say for index, row in df.iterrows(): df.at[index,…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!

You're looping over a DataFrame. It feels natural. It's killing your performance.




# What most tutorials say
for index, row in df.iterrows():
df.at[index, 'tax'] = row['price'] * 0.17






Here's the progression you should actually know:




# Level 1: Vectorization — 10-100x faster 
df['tax'] = df['price'] * 0.17

# Level 2: .apply() when logic is conditional
df['tax'] = df['price'].apply(lambda x: x * 0.17 if x > 0 else 0)

# Level 3: np.where — the fastest option
import numpy as np
df['tax'] = np.where(df['price'] > 0, df['price'] * 0.17, 0)



























Method 1M rows
.iterrows() ~480s
.apply() ~3s
Vectorized / np.where
~0.04s


Pandas wraps NumPy. NumPy operates on entire arrays at the C level. The moment you loop row by row, you throw that away.



The shift: don't think "what do I do to each row?" rather you should ask "what transformation applies to this column?"



That's it. Notebooks that took minutes will now run in seconds.

Intelligence Digest — free The top security news daily · unsubscribe anytime
Community Rating & Social Proof
⭐ Leser-Wertung
–
Ø / 5.0
No reader ratings yet
Was this page helpful?
0
Jetzt Bewertung abgeben
🟢 Niedrig (1-3.9) 🟡 Mittel (4.0-6.9) 🔴 Hoch (7.0-8.9) Kritisch (9.0-10.0)

Related story clusters & sources (vector AI)

2 sources
CVE-2022-46888 | NexusPHP up to 1.7.32 Query Parameter cross site scripting (EUVD-2022-49668)
1 more source
Similar posts
🔍 Verwandte News

Auch interessante Nachrichten Stop Using .iterrows(). Here's What Actually Fast Looks Like

Thematisch verwandte Begriffe: Stop, Using, iterrows, Heres · 6 Treffer

Laden...

Loading videos ...

Laden...

Loading posts ...

Laden...

Loading videos ...

Laden...

Loading posts ...

Laden...

Loading videos ...

Laden...

Loading posts ...

Laden...

Loading videos ...

Laden...

Loading posts ...

Laden...

Loading videos ...

💬 Loading comments…
Pull to refresh
Nächster Beitrag