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
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
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
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
other related topics:
- Rename the column in pandas
- Reindex in python pandas
- Row bind in pandas
- Rank the dataframe in pandas
- Drop the duplicate row in pandas
- Find the duplicate rows in pandas
- Drop the row in pandas with conditions
- Drop or delete column in pandas
for further details on merging , joining and concatenation in pandas one can refer the documentation.