Adding and replacing rows via enlargement
Rows can also be added to a DataFrame
using the .loc
property. The parameter for .loc
specifies the index label where the row is to be placed. If the label does not exist, the values are appended to the data frame using the given index label. If the label does exist, the values in the specified row are replaced.
The following example takes a subset of sp500
and adds a row with the label FOO
:

Note that this change is made in place whether is adds or replaces a row.