Answers for "adding existing column to its own dataframe"

1

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
Posted by: Guest on September-17-2020
0

insert new column to dataframe

group = np.random.randint(10, size=6)
df_new['Group'] = group
Posted by: Guest on May-20-2021

Code answers related to "adding existing column to its own dataframe"

Python Answers by Framework

Browse Popular Code Answers by Language