Skip to main content

Program to add column in to Dataframe

· One min read
Kaustubh Kulkarni

Code >

file.vb
import pandas as pd
data = {'Name': ['Snake', 'Prince', 'Gangsta', 'Wolf'],
'City':['Pune','Nasik','Kolhapur','Bangalore'],
'Qualification': ['Msc', 'MA', 'Msc', 'Msc']}
df = pd.DataFrame(data)
print("Old:\n",df)
df.insert(1, "Age", [21, 23, 24, 21], True)

Output > (OLD)

Output

**Old:**
Name City Qualification
Snake Pune Msc
Prince Nasik MA
Gangsta Kolhapur Msc
Wolf Bangalore Msc

New > (OLD)

NameAgeCityQualification
Snake21PuneMsc
Prince23NasikMA
Gangsta24KolhapurMsc
Wolf21BangaloreMsc