Now that append() is removed in pandas 2.0, what is a short alternative to append() allowing method chaining?
The "What’s new in 2.0.0" section of pandas says:
Removed deprecated
Series.append(),DataFrame.append(), useconcat()instead (GH 35407)
I am looking for something like below to add one row, but within a method chain.
import pandas as pd
df = pd.DataFrame([[4, 5, 6],
[7, 8, 9],
])
df.loc[df.index.size] = [10, 20, 30]
Since you want to use method chaining, use
pipeandconcat:Or, if adding the row is the first step:
Output:
Note that adding a new row is expensive as this creates a full new DataFrame. It's fine if you do it once or twice but don't do it in a loop or this will be very slow for large datasets.