column bind in python pandas – concatenate columns in python pandas

Column bind in python pandas. In this Section we will learn how to concatenate columns to the python pandas dataframe using concat() Function with example i.e. how to column bind two data frames in python pandas.

Column binding is pictographically shown below

column bind in python pandas 0

Create dataframe 1:


import pandas as pd
import numpy as np


#Create a DataFrame

d = {
'Name':['Alisa','Bobby','Cathrine','Madonna','Rocky','Sebastian','Jaqluine',
'Rahul','David'],
'Score1':[62,47,55,74,31,77,85,63,42],
'Score2':[89,87,67,55,47,72,76,79,44]}

df1 = pd.DataFrame(d)
df1

so the resultant dataframe will be

concatenate columns in python pandas – column bind python pandas 1

 

Create dataframe 2:


import pandas as pd
import numpy as np

#Create a DataFrame
d = {
'Score3':[56,86,77,45,73,62,74,89,71]}

df2 = pd.DataFrame(d)
df2

and the resultant dataframe will be

concatenate columns in python pandas – column bind python pandas 2

 

Column bind or concatenate columns of two dataframes in python pandas:

Now lets concatenate or column bind two dataframes df1 and df2. The concatenation of two dataframes are performed with  concat() function by takes two dataframes as argument, axis=1 performs the column wise operation.

import pandas pd

pd.concat([df1, df2], axis=1, ignore_index=True)

argument axis=1 binds the dataframes on column wise, so the resultant column binded dataframe will be

concatenate columns in python pandas – column bind python pandas 3


other related topics:

for further details on merging , joining and concatenation in pandas one can refer the documentation.

previous-small Append or concatenate columns in python pandas – column bind                                                                                                           next_small Append or concatenate columns in python pandas – column bind

Author

  • Sridhar Venkatachalam

    With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.