pandas/frame-growth-in-loop
| Rule | frame-growth-in-loop |
|---|---|
| Pack | pandas |
| Severity | warning |
| Fix | none, edit by hand |
| Library versions | every version |
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.
Message
Section titled “Message”xpd prints this message with the issue. A name that starts with $ stands for code from your file.
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).Browse the other rules of the pandas pack.