Appending new rows
Appending of rows is performed using the .append()
method of the DataFrame
. The process of appending returns a new DataFrame
with the data from the original DataFrame
added first and then rows from the second. Appending does not perform alignment and can result in duplicate index labels.
The following code demonstrates appending two DataFrame
objects extracted from the sp500
data. The first DataFrame
consists of rows (by position) 0
, 1
and 2
, and the second consists of rows (also by position) 10
, 11
and 2
. The row at position 2
(with label ABBV
) is included in both to demonstrate the creation of duplicate index labels.

The set of columns of the DataFrame
objects used in an append do not need to be the same. The resulting data frame will consist of the union of the columns in both, with missing column data filled with NaN
. The following demonstrates this by creating a third data frame using the same index as df1
but having a single column with a name not in df1
.

Now let's...