Skip to content

pandas/frame-growth-in-loop

Pack Severity Fix Versions
pandas warning none, edit by hand All versions

Adding one row at a time with out.loc[len(out)] = row copies the frame on each pass. Collect the rows in a list and build the frame once.

out = pd.DataFrame(columns=output_columns)
for row in rows:
out.loc[len(out)] = row
out = pd.DataFrame(rows, columns=output_columns)

The rule reports out.loc[len(out)] = row inside a loop, which grows the frame by one row at a time.

xpd has no automatic fix, so make the change by hand.

Adding one row at a time copies the frame each time. Collect the rows in a list and build the frame once, as in pd.DataFrame(rows, columns=cols).

See all rules in the pandas pack.