Practice Questions 2024
Practice Questions 2024
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()
Output
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?
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.show()
output
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