To concatenate a new column with a data frame in python.
Read the sample data.
Make it into Data Frame using pandas data frame.
Bind the column using concat(),append().
#import library
import matplotlib.pyplot as plt
import pandas as pd
#10 sample data
data={‘name’:[‘sathish’,’raj’,
‘raja’,’krishna’,’yusuf’],
‘salary’:[100,200,300,400,500],
‘age’:[25,26,25,23,30],
‘rating’:[4,3.24,2.5,2.25,2]}
data1={‘name’:[‘praveen’,’sangee’,
‘ezhil’,’dinesh’,’ganesh’],
‘salary’:[400,300,200,100,50],
‘age’:[29,23,23,24,25],
‘rating’:[2.25,2.5,2.75,3.2,4.2],
‘bonus’:[1400,850,250,750,1000]}
df=pd.DataFrame(data)
df1=pd.DataFrame(data1)
print(“First Data frame”)
print(df)
print(“Second Data frame”)
print(df1)
#Concatenate the bonus
column into data frame1
pd.concat([df, df1[‘bonus’]], axis=1,
gnore_index=True)