O'Reilly logo

Learning pandas - Second Edition by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required