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)] = rowout = pd.DataFrame(rows, columns=output_columns)What the rule reports
Section titled “What the rule reports”The rule reports out.loc[len(out)] = row inside a loop, which grows the frame by one row at a time.
How to fix it
Section titled “How to fix it”xpd has no automatic fix, so make the change by hand.
Diagnostic message
Section titled “Diagnostic message”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.