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

S7 Practice Questions

The document contains a series of programming tasks and questions related to Python, SQL, and data manipulation using Pandas. It covers topics such as correcting code syntax, creating dataframes, plotting graphs, and writing SQL queries for various operations. The tasks range from basic to advanced, requiring knowledge of data structures, functions, and database management.
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)
8 views

S7 Practice Questions

The document contains a series of programming tasks and questions related to Python, SQL, and data manipulation using Pandas. It covers topics such as correcting code syntax, creating dataframes, plotting graphs, and writing SQL queries for various operations. The tasks range from basic to advanced, requiring knowledge of data structures, functions, and database management.
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/ 7

1. The python code written below has syntactical errors.

Rewrite the correct code


and underline the corrections made.
Import pandas as pd
df={"Technology":["Programming","Robotics","3DPrinting"],"Time(
in months)":[4,4,3]}
df= Pd.dataframe(df)
Print(df)

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[ ___________ ])

3. Fill the missing statements to get the given output:


import pandas as pd
rollno=[1,2,3,4,5,6,7]
_______=pd.Series(rollno) #Statement 1
print (p.head(_________)) #Statement 2

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

6. A dictionary ‘stationary’ contains the following: 3


stationary={‘Name’:[ ‘books’, ‘copies’,
‘pencil box’, ‘Pen’],

‘Price’:[ 500,350, 400,250]


Write statements for the following:
a. Create a Dataframe named “stock”
b. Add a column called ‘discount’ with the following data: [ 15, 20, 30, 25]
c. Delete column discount with all values.
7. Differentiate between Single Row and Multi Row Functions?
8. Write a program to create the series that stores the term marks of 10 students.
Find the highest and lowest three marks scored by students.

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.

10. WAP to plot a line chart between two given arrays


A=[4,56,78,23,45,67,89]
B=[0,1,2,3,4,5,6]

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

12. Consider a given Series , D1:


MAX MARKS
TEST 1 30
TEST 2 40
TEST 3 50
TEST 4 100
Write a program in Python Pandas to create the series.
13. Consider the decimal number x with value 54567.8577. Write commands in SQL to:
i. display the whole number without round it off.
ii.round it to 2 places of the decimal.

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

a. Display DESIGNATION wise average salary.


b. Display department wise highest salary.
c. Display the records in the descending order of salary.

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:

NAME DEPARTMENT SALARY


0 Divya HR 95000
1 Mamta Marketing 97000
2 Payal IT 980000
3 Deepak Sales 79000

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:

CLOUMN NAME DATA TYPE CONSTRAINTS


FOOD ITEM VARCHAR(20) PRIMARY KEY
CALORIE INTEGER

18. Consider the given DataFrame ‘Genre’:


Type Code
0 Fiction F
1 Non Fiction NF
2 Drama D
3 Poetry P
Write suitable Python statements for the following:
i. Add a column called Num_Copies with the following data:[300,290,450,760].
ii. Add a new genre of type ‘Folk Tale' having code as “FT” and 600 number of copies.
iii. Rename the column ‘Code’ to ‘Book_Code’.

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

21. Write suitable SQL queries for the following:


i. To calculate the exponent for 3 raised to the power of 4.
ii. To display current date and time.
iii. To round off the value -34.4567 to 2 decimal place.
iv. To remove all the probable leading spaces from the column user_id of the table named
user.
v. To display the length of the string ‘welcome to SMS’.

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 :

i. Display the columns Sal and Bonus


ii. Display the details of the last employee.
iii. Add a new column named ‘Email’ with NULL value for all rows.
iv. To import the proper library/module.
v. Display details of last 3 employee without using tail function

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::

d. Display total number of male and female students..


e. Display gender wise minimum weight.
f. Display the records in the descending order of HEIGHT.
30.

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";

31. Kapil has created following table named exam:


+-------+---------+------------------+-------+ ---+------------------+-------
| RegNo | Name | Subject | Marks |
+-------+---------+------------------+-------+ ---+------------------+-------
| 1 | Sanya | Computer Science | 98 |
| 2 | Sanchay | IP | 100 |
| 3 | Vinesh | CS | 90 |
| 4 | Sneha | IP | 99 |
| 5 | Akshita | IP | 100 |
Page 6 of 7
+-------+---------+------------------+-------+---+------------------+-------
Help him in writing SQL queries to the perform the following task:

1. Insert a new record in the table having following values: [6,'Khushi','CS',85]


2. To change the value “IP” to “Informatics Practices” in subject column.
3. To remove the records of those students whose marks are less than 30 .
4. To add a new column Grade of suitable datatype.
5. To display records of “Informatics Practices” subject.

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy