O'Reilly logo

Learning pandas 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

Concatenating data

Concatenation in pandas is the process of either adding rows to the end of an existing Series or DataFrame object or adding additional columns to a DataFrame. In pandas, concatenation is performed via the pandas function pd.concat(). The function will perform the operation on a specific axis and as we will see, will also perform any required set logic involved in aligning along that axis.

The general syntax to concatenate data is to pass a list of objects to pd.concat(). The following performs a concatenation of two Series objects:

In [2]:
   # two Series objects to concatenate
   s1 = pd.Series(np.arange(0, 3))
   s2 = pd.Series(np.arange(5, 8))
   s1

Out[2]:
   0    0
   1    1
   2    2
   dtype: int64

In [3]:
   s2

Out[3]:
   0    5
   1    6
   2    7
 dtype: int64 ...

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