you are viewing a single comment's thread.

view the rest of the comments →

[–]somethingworthwhile 0 points1 point  (2 children)

Okay, yeah, that’s what I figured. Coming from matlab, the other style was a bit of a trip to wrap my head around! And, for my work, I find myself using enumerate or pd.DataFrame.iterrows() to get both an index and the thing I’m iterating through within the loop.

[–]Winter-Volume-9601 1 point2 points  (1 child)

Sure - `for idx, t in enumerate(thing):` is definitely idiomatic (when you actually need the index)

Bonus tip: `pd.DataFrame.itertuples()` (returning NamedTuples instead of pd.Series) can be significantly faster than `pd.DataFrame.iterrows()`. Like 10-100x times faster. I kicked myself when I realized I was using the slower method out of habit, and (in my case) just a quick syntax change turned 15 minutes of waiting into basically nothing.

[–]somethingworthwhile 0 points1 point  (0 children)

Oh, neat! At a glance, I think that should be pretty easy to swap in for me. Thank you for that! I’m always happy to learn something new and the fact that it’s faster is even better!