pandas add column from list
# creating a list for new column
places = ['Nellore', 'Mumbai', 'Andhra']
# we are using 'Places' as column name
# adding the list to the dataframe as column
dataframe['Places'] = places
pandas add column from list
# creating a list for new column
places = ['Nellore', 'Mumbai', 'Andhra']
# we are using 'Places' as column name
# adding the list to the dataframe as column
dataframe['Places'] = places
how to add new column to dataframe
# Import pandas package
import pandas as pd
# Define a dictionary containing Students data
data = {'Name': ['Jai', 'Princi', 'Gaurav', 'Anuj'],
'Height': [5.1, 6.2, 5.1, 5.2],
'Qualification': ['Msc', 'MA', 'Msc', 'Msc']}
# Convert the dictionary into DataFrame
df = pd.DataFrame(data)
# Declare a list that is to be converted into a column
address = ['Delhi', 'Bangalore', 'Chennai', 'Patna']
# Using 'Address' as the column name
# and equating it to the list
df['Address'] = address
# Observe the result
df
how to add a list to dataframe in python
to_append = [5, 6]
a_series = pd.Series(to_append, index = df.columns)
df = df.append(a_series, ignore_index=True)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us