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 columns through enlargement

A column can be added using the .loc[] property and a slice. The following demonstrates this by adding a new column to a subset of sp500 named PER with all values initialized to 0.

A Series with existing data can also be added in this manner. The following adds the PER column with random data from a series. Since this uses alignment, it is necessary to use the same index as the target data frame.

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