Book Image

Learning pandas - Second Edition

By : Michael Heydt
Book Image

Learning pandas - Second Edition

By: Michael Heydt

Overview of this book

You will learn how to use pandas to perform data analysis in Python. You will start with an overview of data analysis and iteratively progress from modeling data, to accessing data from remote sources, performing numeric and statistical analysis, through indexing and performing aggregate analysis, and finally to visualizing statistical data and applying pandas to finance. With the knowledge you gain from this book, you will quickly learn pandas and how it can empower you in the exciting world of data manipulation, analysis and science.
Table of Contents (16 chapters)

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 will be covered in more detail in Chapter 11, Combining, Relating, and Reshaping Data.

It is possible to have duplicate column names as a result of a concatenation. To demonstrate this happening, let's recreate rounded_price but...