Research breakthrough possible @S-Logix pro@slogix.in

Office Address

  • 2nd Floor, #7a, High School Road, Secretariat Colony Ambattur, Chennai-600053 (Landmark: SRM School) Tamil Nadu, India
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to bind column into a data frame using python?

Description

To concatenate a new column with a data frame in python.

Process

  Read the sample data.

  Make it into Data Frame using pandas data frame.

  Bind the column using concat(),append().

Sample Code

#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)

Screenshots
To bind column into a data frame using python