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

Practice Questions 2024

Uploaded by

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

Practice Questions 2024

Uploaded by

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

Q1.The number of students in 7 different classes is given below.

Represent this
data on the line graph.
Class VI VII VIII IX X XI XII
Number of 50 55 60 53 62 51 64
Students

Code:
import matplotlib.pyplot as plt
cl=['VI','VII','VIII','IX','X','XI','XII']
stu=[50,55,60,53,62,51,64]
plt.plot(cl,stu,COLOR="ORANGE")
plt.xlabel("CLASS")
plt.ylabel("NO. OF STUDENTS")
plt.title("NO. OF STUDENTS IN DIFFERENT CLASSES")
plt.show()

Q2.The popularity of different programming languages on scale of 10is given in


the below table. Represent this data on the bar graph.

Programming JAVA HTML CODE PYTHON BASIC


Language FUSION
On scale 9 7 8 9.5 5
CODE:
import matplotlib.pyplot as p
x=['JAVA', 'HTML','COBOL','PYTHON','BASIC']
y=[9,7,8,9.5,5]
p.title('Popularity of different programming languages')
p.xlabel("Programming Language")
p.ylabel("Popularity on scale of 10 ")
p.bar(x,y,color=’red’)
p.show()

Output

Q3.Write the python code for the table shows passenger

four wheeler's fuel rates in miles per gallon for several years.

Make a LINE GRAPH of the data. During which 2-year period did the fuel rate
decrease?

YEAR 2015 2016 2017 2018 2019


RATE 31.0 30.8 31.4 31.8 32.0
CODE
import matplotlib.pyplot as plt

Yr=[2015,2016,2017,2018,2019]

rate=[31.0,30.8,31.4,31.8,32.0]

plt.plot(Yr,rate,marker='o',color='g')

plt.xlabel("Year")

plt.ylabel("Rate miles/gallon")

plt.title("Fuel Rate Comparision")

plt.show()

output

Ans year 2015-2016

Q4.Write a python program to create a dataframe with details of Alex as subjects -


Economics,Accountancy,English,History,Computer Science and marks -
94,91,95,96,97 and Calculate sum of all marks

CODE :
import pandas as pd
import numpy as np
data = {'Subjects':['Economics’,Accountancy', 'English',’History’,
'Computer Science'],
'marks': [ 94,91,95,96,97]}
df = pd.DataFrame(data)
print("Sum of Marks:")
print(df['marks'].sum())

Output:

Sum of Marks:

473

Q5.Write a Pandas program to select the rows where the height is not known, i.e.
is NaN.
'name': ['Asha', 'Radha', 'Kamal', 'Divy', 'Anjali'],
'height': [ 5.5, 5, np.nan, 5.9, np.nan],
'age': [11, 23, 22, 33, 22]
solution
import pandas as pd
import numpy as np
pers_data = {‘name': ['Asha', 'Radha', 'Kamal', 'Divy','Anjali'],
'height': [ 5.5, 5, np.nan, 5.9, np.nan],
'age': [11, 23, 22, 33, 22]}
labels = ['a', 'b', 'c', 'd', 'e']
df = pd.DataFrame(pers data , index=labels)
print("Persons whose height not known:")
print(df[df['height'].isnull()])
Jerry 3 Sri Nagar
0
Roopal 2 Jodhpur Q6. Write a python program to filter
5 records from rows ,based on criteria
John 2 New Delhi on the dataframe
4 STUDENT such as
Roopal 2 Jodhpur
5
Roopal 2 Jodhpur
5
Rishika 2 Mumbai
0
John 3 Chennai
5
1)duplicate rows and
2) name='John'
3) conditions like age >25.
import pandas as pd
students = [('Jerry', 30, 'Sri Nagar'),
('Roopal', 25, 'Jodhpur'),
('John', 24, 'New Delhi'),
('Roopal', 25, 'Jodhpur'),
('Roopal', 25, 'Jodhpur'),
('Rishika', 20, 'Mumbai'),
('John', 35, 'Chennai')]
# Create a DataFrame object
dfobj = pd.DataFrame(students,
columns=['Name', 'Age', 'City'])
print(dfobj)
print("Display duplicated row")
print(dfobj.duplicated())
print("Display Details of John")
print(dfobj[dfobj.Name=='John'])
print("Display details where age above then 25")
print(dfobj[dfobj.Age>25])
output
Name Age City
0 Jerry 30 Sri Nagar
1 Roopal 25 Jodhpur
2 John 24 New Delhi
3 Roopal 25 Jodhpur
4 Roopal 25 Jodhpur
5 Rishika 20 Mumbai
6 John 35 Chennai
Display duplicated row
0 False
1 False
2 False
3 True
4 True
5 False
6 False
dtype: bool
Display Details of John
Name Age City
2 John 24 New Delhi
6 John 35 Chennai
Display details where age above then 25
Name Age City
0 Jerry 30 Sri Nagar
6 John 35 Chennai

Q7.Consider the following table DRESS .write the SQL commands for the
statements (i) to (iv) and give the output for the sql queries (v) to (vi)

TABLE:DRESS

DCODE DESCRIPTION PRICE MCODE LAUNCH DATE


10001 FORMAL SHIRT 1250 M001 2008-01-12
10020 FROCK 750 M004 2007-09-09
10012 INFORMAL 1450 M002 2008-06-06
SHIRT
10019 EVENING GOWN 850 M003 2008-06-06
10090 TULIP SKIRT 850 M002 2007-03-31
10023 PENCIL SKIRT 1250 M003 2008-12-19
10089 SLACKS 850 M003 2008-10-20
10007 FORMAL PANTS 1450 M001 2008-03-09
10009 INFORMAL PANT 1400 M002 2008-10-20
10024 BABY TOP 650 M003 2007-04-07
i)To display DCODE and DESCRIPTION of each dress in descending order of
DCODE.
ii)To display the details of all the dresses which have LAUNCHDATE between
2007-12-05 and 2008-06-20.(inclusive of both dates)
iii)To display the average PRICE of all the dresses which are made up of material
with MCODE as M003.
iv)To display material wise highest to lowest price of dresses from DRESS table
v)SELECT SUM (PRICE) FROM DRESS WHERE MCODE=’M001’;
vi)SELECT COUNT(DISTINCT PRICE) FROM DRESS;
solution

Q8.Consider the table: GARMENT and write the below queries:

GCODE GNAME SIZE COLOUR PRICE


111 TSHIRT XL RED 1400.00
112 JEANS L BLUE 1600.00
113 SKIRT M BLACK 1100.00
114 LADIES JACKET XL BLUE 4000.00
115 TROUSER L BROWN 1500.00
116 LADIES TOP L PINK 1200.00

1) To display the name of the garments that are available in “XL”


2) To display code and names of those garments that have their names starting with
“LADIES”.
3) To display garment name,codes and prices of those garment that have price in the
range 1000.00 to 1500.00
4) To change the colour of the garment with code 116 to “ORANGE”.
5) To get the average price of the garment with size “L”.
6) To display the records of those garments that have their size “XL” in ascending
order.
7) To delete the record whose price is greater than 3500.00.

Q9.To display the max price form the table garment.


Observe the following tables and write the queries on the basis the given tables :-
Table:EMPLOYEE
1. To display list of all employees below 25 years old.
2. To list names and respective salaries in descending order of salary.
3. To count the number of employees with names starting with ‘K’
4. To list names and addresses of those persons who have ‘Delhi’ in their address.
5. To list out all the employees whose salary is in between 70000 and 80000
6. To update salary of ‘Paul’ to 80000.
7. To list the details of employee who has minimum salary.

Ans -1 SELECT * FROM EMPLOYEE WHERE AGE<25;

2.SELECT NAME ,SALARY FROM EMPLOYEE ORDER BY SALARY DESC;

3.SELECT COUNT(*) FROM EMPLOYEE WHERE NAME LIKE ‘K%’;

4.SELECT NAME ,ADDRESS FROM EMPLOYEE WHERE ADDRESS LIKE


‘%Delhi%’;

5.SELECT * FROM EMPLOYEE WHERE SALARY BETWEEN 70000 AND


80000;

6.UPDATE EMPLOYEE SET SALARY =80000 WHERE NAME=PAUL;

7.SELECT * FROM EMPLOYEE WHERE SALARY =(SELECT


MIN(SALARY) FROM EMPLOYEE);

You might also like