0% found this document useful (0 votes)
4 views

Creating DataFrame 2024

Nsmsmasmakkkajmm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Creating DataFrame 2024

Nsmsmasmakkkajmm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Manglembi maam IP/CS Educator(Sape Tutorial centre)(10 years experience) mobile:7085315830 (Address:khagempalli Huidrom leikai)

Creating and displaying a dataframe:


1. Create empty DataFrame
2. Creating a DataFrame from a 2d dictionary having value as list
3. Creating a DataFrame from a 2d dictionary having value as series object (dict of series)
4. Creating a DataFrame from a 2d dictionary having value as series object (dict of series) (with different index value)
5. Creating a DataFrame object from 2d dictionary having values as dictionary
6. Creating a DataFrame object from 2d dictionary having values as dictionary(Inner dictionary had non-matching index)
7. Creating a DataFrame from a 2d dictionary having value as 2-d ndarray
8. Creating a DataFrame from a 2D list
9. Creating a DataFrame from a 2d dictionary having value as 2-d ndarray
10. Creating a DataFrame from a 2D list/2D-ndarray (If the rows of ndarray and list differ in length)
11. Creating a DataFrame object from a list of dictionary
12. Creating a DataFrame object from another DataFrame object(Shallow vs Real copy)

Manglembi maam IP/CS Educator(Sape Tutorial centre)(10 years experience)


mobile:7085315830 (Address:khagempalli Huidrom leikai)
Manglembi maam IP/CS Educator(Sape Tutorial centre)(10 years experience) mobile:7085315830 (Address:khagempalli Huidrom leikai)

#inner dictionary had non matching index

Manglembi maam IP/CS Educator(Sape Tutorial centre)(10 years experience)


mobile:7085315830 (Address:khagempalli Huidrom leikai)
Manglembi maam IP/CS Educator(Sape Tutorial centre)(10 years experience) mobile:7085315830 (Address:khagempalli Huidrom leikai)

Manglembi maam IP/CS Educator(Sape Tutorial centre)(10 years experience)


mobile:7085315830 (Address:khagempalli Huidrom leikai)
Manglembi maam IP/CS Educator(Sape Tutorial centre)(10 years experience) mobile:7085315830 (Address:khagempalli Huidrom leikai)

Important questions for Dataframe creation:


1. Consider the lists Name=[‘S1’,’S2’,’S3’], Age=[15,14,13],Gender=[‘M’,’F’,’M’] and Rollno=[11,12,13]
Write python code that create DataFrame student with Name, Age and Gender as columns and Rollno as
rowlabel?
2. Write a Python program to create the following DataFrame using a list of dictionaries.
Product Price

0 Laptop 60000
1 Desktop 45000
2 Monitor 1500
3 Tablet 3000

3. Write a Python program to create a DataFrame using a list of dictionaries:


Name Department Salary
0 Divya HR 95000
1 Mamta Marketing 97000
2 Payal IT 98000
3 Deepak Sales 79000
Manglembi maam IP/CS Educator(Sape Tutorial centre)(10 years experience)
mobile:7085315830 (Address:khagempalli Huidrom leikai)
Manglembi maam IP/CS Educator(Sape Tutorial centre)(10 years experience) mobile:7085315830 (Address:khagempalli Huidrom leikai)
4. Write a python code to create an empty dataframe?
5. Write a small Python code to create a DataFrame with headings ( a and b) from the list given below:
[[10,20],[30,40],[50,60],[70,80]]
6. Write a Python program to create the following DataFrame using a list of dictionaries.
A B C
0 21 12 69
1 45 45 84
2 23 86 70
3 17 33 78

7. Consider the DataFrame MyDF given as below and create a DataFrame using list of dictionaries:
0 Emp_id Name Designation City Salary
1 E001 Ritvi Clerk Gurugram 32000
2 E025 Riya Programmer Delhi 65000
3 E034 Gaurav Data Analyst Bangalore 95000
4 E016 Kanishka Manager Mumbai 87000

8. Kabir, a data analyst, has stored the voter’s name and age in a dictionary. Now, Kabir wants to create a list of
dictionaries to store data of multiple voters. He also wants to create a DataFrame from the same list of
dictionaries having appropriate row label as shown below:
Voter_Name Voter_Age
Ar1001 Arjun 35
Ba3002 Bala 23
Go4002 Govind 25
Dh4007 Dhruv 19
Na6005 Navya 18

9. Write Python code to create a dataframe df (runs scored by batsman in last three years ) with appropriate row
labels from the dictionary given below :

{‘Virat’:[1000,962,1035],’Rohit’:[635,580,602],’Surya’:[1200,1008,1258]}

10. A dictionary smarks contains the following data:


Smarks={‘name’:[‘rashmi’,’harsh’,’priya’],’grade’:[‘A1’,’A2’,’B1’]}
Write a statement to create DataFrame called df.
Assume that pandas has been imported as pd.
11. Write a small python code to create a dataframe with headings(‘Rollno’ and ‘Name’) using the list given below :
[[1,’Shayam’],[2,’Mohan’],[3,’Kamla’],[4,’Kamalesh’]]
12. Create a dataframe to store roll, name, sec and marks of 5 students.

Manglembi maam IP/CS Educator(Sape Tutorial centre)(10 years experience)


mobile:7085315830 (Address:khagempalli Huidrom leikai)

You might also like