1#using the insert function:
2df.insert(location, column_name, list_of_values)
3#example
4df.insert(0, 'new_column', ['a','b','c'])
5#explanation:
6#put "new_column" as first column of the dataframe
7#and puts 'a','b' and 'c' as values
8
9#using array-like access:
10df['new_column_name'] = value
11
12#df stands for dataframe
1# Import pandas package
2import pandas as pd
3
4# Define a dictionary containing Students data
5data = {'Name': ['Jai', 'Princi', 'Gaurav', 'Anuj'],
6 'Height': [5.1, 6.2, 5.1, 5.2],
7 'Qualification': ['Msc', 'MA', 'Msc', 'Msc']}
8
9# Convert the dictionary into DataFrame
10df = pd.DataFrame(data)
11
12# Declare a list that is to be converted into a column
13address = ['Delhi', 'Bangalore', 'Chennai', 'Patna']
14
15# Using 'Address' as the column name
16# and equating it to the list
17df['Address'] = address
18
19# Observe the result
20df