Creating a Pandas DataFrame
Get Job-Ready: Data Analysis using Python with 70+ Projects Start Now!!
Program 1
# Data Frame(Df)
# Create Empty Df
# Create Df using list
# Create Df using dictonary
# Create Df using numpy array
# Create Df using Clipboard
# Create Df using tuple
# Create Df using Excel file
# Create Df using CSV file
import pandas as pd
import numpy as np
# Create Df using CSV file
# myfile="D://mypandas/employee.csv"
# #print(type(myfile))
# df=pd.read_csv(myfile)
# print(df)
# Create Df using Excel file
# myfile="D://mypandas/mydata.xlsx"
# #print(type(myfile))
# df=pd.read_excel(myfile,sheet_name='employee')
# print(df)
# Create Df using Clipboard
# df=pd.read_clipboard()
# print(df)
# # Create Df using tuple
# data=[(1,'vivek',8000),(2,'vikas',38000),(3,'rahul',78000)]
# df=pd.DataFrame(data)
# print(df)
# # Create Df using dictonary
# empdata={'empid':[1,2,3,4,5],'empname':['Rahul','Nilesh','Monu','Sonu','Ranu'],'salary':[70000,40000,60000,25000,12000]}
# df=pd.DataFrame(empdata)
# print(df)
# # Create Df using numpy array
# npar=np.array([[10,20,30,88],[40,50,60,66],[70,80,90,44]])
# df=pd.DataFrame(npar)
# print(df.shape)
# print(df.ndim)
# Create Df using list
# mylist=[10,20,30,40,50,60,70,80,90,100]
# df=pd.DataFrame(mylist)
# print(df.ndim)
# Create Empty Df
#df=pd.DataFrame()
#print(type(df))
We work very hard to provide you quality material
Could you take 15 seconds and share your happy experience on Google

