Vectorization vs. For-Loop

1. The Python For-Loop
for i in range(5):
  rng[i] = tmax[i] - tmin[i]
Idxtmaxtmintemp_range
019.611.1
121.812.3
224.812.7
326.214.0
428.115.2
Time: 0.00s
2. Pandas Vectorization
# Math applied instantly to entire array
rng = data["tmax"] - data["tmin"]
Idxtmaxtmintemp_range
019.611.1
121.812.3
224.812.7
326.214.0
428.115.2
Time: 0.00s
Click the buttons above to compare how Python loops vs. Pandas vectorization process data.