What is the most efficient way to loop through dataframes with pandas?
I’m looking to iterate row by row through a pandas
DataFrame. The way I’m doing it so far is as follows:
for i in df.index: do_something(df.ix[i])
Is there a more performant and/or more idiomatic way to do this? I know about apply, but sometimes it’s more convenient to use a for loop. Thanks in advance.
You should use
df.iterrows(). Though iterating row-by-row is not especially efficient since Series objects have to be created.