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 using concatenation

Both the [] operator and .insert() method modify the target data frame in-place. If a new data frame with the additional columns is desired (leaving the original unchanged) then we can use the pd.concat() function. This function creates a new data frame with all of the specified DataFrame objects concatenated in the order of specification.

This following creates a new DataFrame with a single column containing the rounded price. It then uses pd.concat() with axis=1 to signify that the given DataFrame objects should be concatenated along the columns axis (as compared to rows which would use axis=0) .

Concatenation ...

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