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

DF1

Uploaded by

Pete Santhosh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

DF1

Uploaded by

Pete Santhosh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

1) Consider the following dataframe and do as directed:

import pandas as pd
d={‘Mouse’:[150,200,300,400],‘Keyboard’:[180,200,190,300], ‘Scanner
’:[200,280,330,450]}
df=pd.DataFrame(d,index=[‘Jan’,’Feb’,’March’,’April’])

i) Write code to access data of Mouse and Scanner columns.


ii) Write code to access data of scanners using loc[].

2) Write a python code to create a data frame with appropriate headings from
the list given below:

['S101', 'Amy', 70], ['S102', 'Bandhi', 69], ['S104', 'Cathy', 75], ['S105', 'Gundaho', 82]

3) Use the Data Frame created in below to do the following:

import pandas as pd
d = {2014:[100.5,150.8,200.9,30000,4000],
2015:[12000,18000,22000,30000,45000],
2016:[20000,50000,70000,10000,125000],
2017:[50000,60000,70000,80000,90000]}
Sales=pd.DataFrame(d,index=['Madhu',"Kusum","Kinshuk","Ankit","Shruti"])
print(Sales)

i) Display the row labels of Sales


ii) Display the column labels of Sales.
iii) Display the data types of each column of Sales.

4) Consider the following dataframe:

import pandas as pd
d={‘Name’:[‘Ann’, ‘Manav’,’Sanjay’, ‘Balu’,’Shiv’],

‘PT1’:[35,42,43,44,39],’Weekly_Test’:[24,16,19,22,23]}

Df=pd.DataFrame(_______________) # Statement1

print(_____________________) #Statement2

print(df[::-2]) #Statement3

df=df.___________ #Statement4
df____________ #Statement5

i. Create a dataframe with index as given - statement 1.

ii. Print the name and PT1 marks who got more than 23 –Statement 2

iii. What will be the output of statement 3?

iv. Print the number of values in the dataframe object.

v. Display the mark of Lux in Weekly Test.

5) Create a DataFrame using a dictionary that stores Age, Location and Name
of candidates applied for an International Sports Event. Screen shot as
follows:

Note: Pandas library has been imported as pd.

6) Consider the given DataFrame ‘College’:

Write suitable Python statements for the following:


i. Add a column called Tax with the following data:
[35,50,60,25].
ii. Add a new college named ‘LMN' having Fee 1500.
iii. Remove the column Tax.

7) Mr. Tarun, a data analyst has designed the DataFrame DF1 that contains
data about Cyber Security Olympiad with ‘CS1’, ‘CS2’, ‘CS3’, ‘CS4’,
‘CS5’ as indexes shown below. Answer the following questions:

A. Predict the output of the following python statement:


i. DF1.shape
ii. DF1[2:4]
B. Write Python statement to display the data of DIST column of indexes
CS2 to CS4.
C. Write Python statement to compute and display the difference of data of
TOT_STUD column and FIRST column of the above given DataFrame.

8) Consider the following DataFrame.


import pandas as pd
df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
print(df)
A B
0 1 4
1 2 5
2 3 6
Write commands to:
i. Add a new column ‘C’ to the DataFrame with values 7,8,9.
ii. Rename the column name from ‘B’ to ‘D’ of DataFrame.

9) Carefully observe the following code:


import pandas as pd
d={'Pcd':['P01','P02','P03','P03'],
'title':[40,31,35,29],
'Price'':[85,76,129,730],
'qty':[500,200,50,70]}
lib=pd.DataFrame(d)
print(lib)
Answer the following:
i. List the index of the DataFrame lib
ii. List the column names of DataFrame lib.

10) Write a Python code to create a DataFrame with appropriate column headings
from the list given below:
[[101,'Simran',98],[102,'Rajveer',95],[103,'Samar' ,96],[104,'Shakti',88]]

11) Write a program in Python Pandas to create the following DataFrame toppers
from a Dictionary:
T_NO Name PB1 PB2
1 Pavan 90 80
2 Sugandha 85 75
3 Pulkita 70 72
4 Sahil 69 71
Perform the following operations on the DataFrame :
i) Add both the marks from PB1 and PB2 of a student and assign to column
“Final”.
ii) Add a new row with values (5, Raman,60,85)
iii) Delete the column PB2

12) Write a program in Python Pandas to create the following DataFrame Student
from Dictionary of Series:

Perform the following operations on the DataFrame :


i) Predict the output of the following python statement:
a. df.shape b. df[2:4]
ii) Display the Marks of Prakash and Meena from the DataFrame.
iii) Display only Name column from Dataframe

13) Observe the following code and write statements for the below given questions:
import pandas as pd
player1={‘IG1’:34,’IG2’:0,’IG3’:23}
player2={‘IG1’:21,’IG2’:10,’IG3’:39}
pl={‘p1’:player1,’p2’:player2}
df=pd.DataFrame(pl)
a) Display data of player scored more than 30 runs
b) Display all rows of first inning of all players

14) Write python code to create a dataframe by using following data:


[[201,’Manoj’,4500],[202,’Dhara’,3200],[203,’Mohini’,2300]]

i. Dataframe name should be cust


ii. Use column headings as: cust_id,cust_name and amount

15) Consider the following dataframe ‘temperature’:

Write suitable python code to:


a) Add new column min with these data: [25,22,19,28]
b) Add new city Mahesana with 30 value
c) Delete column min

16) Write the output of the following code


import pandas as pd
D_F=pd.DataFrame({'Name':['Priya','Jaya','Ashok'],'Age':[19,18,16],
'Weight':[42,55,60]})
print('Original Dataframe')
print(D_F)
print('\nTranspose Dataframe')
print(D_F.T)

17) Write a program to read from a CSV file name “emp.csv”. and create a dataframe
from it but your dataframe should not use file column header rather should use
own column heading as ID, Name, Designation, Salary. Also print the maximum
salary given to an employee.

18)
Write a python code with the following specifications.
i) Create four dictionaries naming emp1, emp2, emp3, emp4 to store the details
of four employees of the month with emp_no, name, salary.
ii) Create a dataframe from those dictionaries and display it.
iii) Create a series with the employee name from the created dataframe and
display the same.
iv) Display the sales man who earns less than 45000.
v) Increase the salary by 3% and display the same.

19) Consider the following given dataframe ‘df1’:

Write the Python code statement to:

i) Find all rows with the label “Apple”. Extract all columns.

ii) List the fruits with count more than 10.

iii) Extract 2nd, 3rd, and 4th rows.


iv) List the columns with the label “Count” and “Price”.

v) Display first five rows

20) Given the following dataframes:

Write the commands to do the following operations on the dataframes given


above:
(i) To add dataframes df1 and df2.
(ii) To subtract 100 from df2
(iii) To increase the df1 by 72%
(iv) To check for missing values in dataframe

21) A dictionary Grade contains the following:


Grade={'Name':['rashmi','Harsh','Ganesh','Priya','Vivek'],'Grade':['A1','A2','B1','A
1','B2']}
Write statements for the following:
i. Create a dataframe name “Gr”.
ii. Add a column called „marks‟ with the following data: [97,92,95,89,96,82]

22) Write a Python code to create the following dataframe books suing Python
Pandas. Use any method of dataframe creation that you have learnt:
Give index as „B1‟, „B2‟, „B3‟, „B4‟

23) Mr. Sam, a data analyst has designed the DataFrame df that contains data about
Computer Olympiad with „CO1‟, „CO2‟, „CO3‟, „CO4‟, „CO5‟ as indexes
shown below. Answer the following questions:

Predict the output of the following python statement:


i. df.shape
ii. df[2:4]
iii. Write Python statement to display the data of Topper column of indexes CO2
to CO4.
iv. Write Python statement to compute and display the difference of data of
Tot_students column and First_Runnerup column of the above given DataFrame.

24) Write python code to create the following dataframe books using python
pandas. Use any method of dataframe creation that you have learnt:
Given index as ‘A1’,’A2’,’A3’.

25) A dictionary contains the following:


Toys={Name:[‘Talkingtom’,’blocks’,’NumberGame’,’Ludo’],’price’:[400,250,300,1
50]}
Write statement for the following:
(i)Create a dataframe name”stock” using dictionary “toys”
(ii) Add a column called ”discount” with the following data:[30,40,15,25]
(iii)Delete column” discount” with all values

*******************************

You might also like