Append rows to a pandas DataFrame without making a new copy

PythonPandas

Python Problem Overview


The pandas documentation includes a note:

>Note Unlike list.append method, which appends to the original list and returns nothing, append here does not modify df1 and returns its copy with df2 appended.

How can I append to an existing DataFrame without making a copy? Or in the terms of the note how can I modify df1 in place by appending df2 and return nothing?

Python Solutions


Solution 1 - Python

See https://stackoverflow.com/questions/19365513/how-to-add-an-extra-row-to-a-pandas-dataframe/19368360#19368360

Upcoming pandas 0.13 version will allow to add rows through loc on non existing index data.

Description is here and this new feature is called Setting With Enlargement.

Solution 2 - Python

Why not use concat?

df = pd.concat([df, pd.DataFrame(new_data)])

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questioncameron.brackenView Question on Stackoverflow
Solution 1 - PythonNasser Al-WohaibiView Answer on Stackoverflow
Solution 2 - PythonmattexxView Answer on Stackoverflow