S7 Practice Questions
S7 Practice Questions
2. Complete the given Python code to get the required output as: Rajasthan
import _________ as pd
di = {'Corbett': 'Uttarakhand', 'Sariska': 'Rajasthan', 'Kanha':
'Madhya Pradesh’,'Gir':'Gujarat'}
NP = ___________. Series( _____ )
print(NP[ ___________ ])
4. Consider two objects L and S. L is a list whereas S is a Series. Both have values 20, 40,90, 110.
What will be the output of the following two statements considering that the above objects
have been created already.
print (L+2) #Statement 1
print (S+2) #Statement 2
5. Mr. Harry wants to draw a line chart using a list of elements named LIST. Complete the code to
perform the following operations:
a. To plot a line chart using the given LIST
b. To give a y-axis label to the line chart named "sample number".
import matplotlib.pyplot as PLINE
LIST=[10,20,30,40,50,60]
______________ #Statement 1
______________ #Statement 2
Page 1 of 7
9. Write a program to create a series from list marks and taking index values from list roll no. Show all
elements that are above 80 marks.
11. Write Python code to create the following DataFrame df1 using Python Pandas. Use anymethod
ofDataFrame creation that you have learned: 2
Name Class Marks
Arjun XII 95
Ruchi X 84
Prerna XI 90
Himali XI 75
14. Based on the SQL table EMPL, write suitable queries for the following::
EmpNo. Ename Salary Designation Dept
0 1 AYUSH 10000 Manager 10
1 2 ADHYAN 15000 Clerk 20
2 3 ADITYA 5000 Director 10
3 4 ANIKET 25000 Manager 30
4 5 DEV 28000 Director 10
5 6 DHRUV 6000 Clerk 20
6 7 DUSHYANT 4500 Clerk 40
7 8 ASHITA 12000 Peon 10
8 9 ESHA 62000 Director 20
9 10 MAITRI 100000 Chairman 10
Page 2 of 7
15. Create a DataFrame in Python from the given list:
**‘Divya’,’HR’,95000+,*‘Mamta’,’Marketing’,97000+,*‘Payal’,’IT’,980000+,
*‘Deepak’,’Sales’,79000++
Also give appropriate column headings as shown below:
16. Poonam wants to display first 3 elements from series S. She wrote the following program:3
import pandas as pd
S=pd.Series([10,20,30,40,50], index =[1,2,3,4,5])
print(S.iloc[1:3])
But she did not get the desired result.
a. Rewrite the above program with necessary changes to help her get the desired output.
b. Write the statement to display the values which are greater than equal to 30.
c. Write the statement to change the index name of the Series as "My Index".
17. Write MySQL statements for the following: i. To create a database named FOOD. ii. To create a table named
Nutrients based on the following specification:
19. Sunita is working as DBA in Infosys, help her by writing answers of following queries
based on given table:
Page 3 of 7
a. Write a query to display the year of DOB.
b. Write a query to display the month of most recent DOJ.
c. Write a query to display the details all those employees who joined in the month of May.
d. Write a query to count total number of employees who joined in the year 2022.
20. Write the output of the given statement(s), based on the given DataFrame named "df":
a. print(df.loc[:1])
b. df["Married"]=False
print(df.loc[2:,["Name","Married"]])
c. df.weight[1] ans :123
d. print(df.age)ANS 15,20,18
22. Write a program to plot a bar graph and show the population of 6 years.
Consider thefollowing data to plot a graph.
population(in cr.)=[50,34,30,67,65,70,95]
year=[2010,2011,2012,2013,2014,2015,2016]
23. HR Department of ABC Tech has created a dataframe ‘df1’ to store data
about name, salaries and bonus paid to their employees. The headings are Name,
Salary and Bonus. Give the commands to do the following :
Page 4 of 7
35. Write a Python program to draw a graph with a suitable label in the X axis and Y axis and a
title. The output shown in the following screenshot.
Also give a suitable python statement to save this chart.
24. Write a Pyhton program to draw a line with a suitable label in the X axis and Y axis
and a title. The code snippet gives the output shown in the following screenshot.
25. Write a code to draw the following bar graph representing the number of students in
eachclass:.
Page 5 of 7
26. Write a python program to draw a histogram with following information:
[10,15,10,10,10,15,20,20,20,20,20,25,25]
The histogram should have followed information
a. X-axis label should be score and Y-axis should be Frequency
b. The title should be Frequency of Score
c. The colour of histogram should be cyan with 10 bins
d. Also give a suitable python statement to save this chart.
e. Use proper import statements in the program
27. Mr Ramesh wrote a Query to find the sum of bonus earned by the employees of WEST zone:
Select zone, Total (bonus) from employee having zone =”west”;
But he got an error, find the error. Write correct query by removing the possible error/logic.
28. Carefully observe the following code:
import pandas as pd
x=[[100,200,300],[10,20]]
df=pd.DataFrame(x)
print(df)
Answer the following:
i. Display the dataframe
ii. Write the syntax for displaying size and shape of the above dataframe.
29. Based on the SQL table STUDENT, write suitable queries for the following::
Predict the output of the following queries based on the table PURCHASE given above:
1. SELECT LEFT(CNAME,2) FROM PURCHASE WHERE QUANTITY>=100;
2. SELECT QUANTITY/2 FROM PURCHASE WHERE MONTH(DOP)=10;
3. SELECT SUM(QUANTITY) "TOT SALE" FROM PURCHASE WHERE CITY=”CHANDHIGARH";
32. Consider the two objects s1 and s2. s1 is a list whereas s2 is a Series. Both have values100,
200, 300, 400, 500.
What will be the output of the following two statements considering that the aboveobjects
have been created already?
a. print(s1 * 2) ii) print(s2 * 2)
33. Given the dataset for Employee: 4
Data=*‘Ravi’,38,’Accountant’+,*‘Sanjay’,44,’Cashier’+,
*Ramesh’,35,’Clerk’+,*‘Nipun’,53,’Manager’+
Write a program to convert this dataset into dataframe and then perform pivoting on
the dataframe. Also draw a histogram based on Employee data.
34.
Page 7 of 7