XII IP PRACTICAL LIST 2022-23-1
XII IP PRACTICAL LIST 2022-23-1
PRACTICAL LIST
CLASS: XII
SUB: INFORMATIC PRACTICES
SESSION:2023-24
import pandas as pd
import numpy as np
exam_data = {'name': ['Aman', 'Kamal', 'Amjad', 'Rohan', 'Amit',
'Sumit', 'Matthew', 'Kartik', 'Kavita', 'Pooja'],
'perc': [79.5, 29, 90.5, np.nan, 32, 65, 56, np.nan, 29, 89],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no',
'yes']}
labels = ['A', 'B', 'C', 'B', 'E', 'F', 'G', 'H', 'I', 'J']
df = pd.DataFrame(exam_data , index=labels)
print("Number of student whoes percentage more than 70:")
print(df[df['perc'] > 70])
3. Filter out rows based on different criteria such as duplicate rows.
import pandas as pd
data={'Name':['Aman','Rohit','Deepika','Aman','Deepika',
'Sohit','Geeta'],
'Sales':[8500,4500,9200,8500,9200,9600,8400]}
sales=pd.DataFrame(data)
# Find duplicate rows
duplicated = sales[sales.duplicated(keep=False)]
print("duplicate Row:\n",duplicated)
#Method 1
print(sales[2018])
#Method 2
print(sales.loc[:,2018])
#Method 2
print(sales.loc[sales.index.isin(["Kapil","Mohini"]),[2019,2020]])
print("Add Data:")
sales.loc["Nirali"]=[221, 178, 165, 177]
print(sales)
Sales.drop(columns=2018,inplace=True)
print(Sales)
sales=sales.drop("Shikhar",axis=0)
#sales.drop("kinshuk")
print(sales)
sales=sales.rename({"Kamini":"Rani","Kapil":"Anil"},axis="index")
print(sales)
sales.loc[sales.index=="Mohini",2018]=150
print(sales)
7.Create a Data Frame quarterly sale where each row contains the
item category, item name, and expenditure. Group the rows by the
category, and print the total expenditure per category.
import pandas as pd
Col=['itemcat','itemname','expenditure']
# Create the pandas DataFrame
qrtsales = pd.DataFrame(data,columns=Col)
# print dataframe.
print (qrtsales)
qs=qrtsales.groupby('itemcat')
print('Result after Filtering Dataframe')
print(qs['itemcat','expenditure'].sum())
8.Write a Pandas program to count the number of rows and columns of a
Data Frame.
import pandas as pd
import numpy as np
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James',
'Emily', 'Michael', 'Matthew', 'Laura', 'Kevin', 'Jonas'], 'score': [12.5, 9,
16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19], 'attempts': [1, 3, 2, 3, 2, 3, 1,
1, 2, 1], 'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
df = pd.DataFrame(exam_data , index=labels) t
total_rows=len(df.axes[0])
total_cols=len(df.axes[1])
print("Number of Rows: "+str(total_rows))
print("Number of Columns: "+str(total_cols))
#Method 1
print("Using tail function:")
print(Sales.tail(2))
#Method 2
print("Using iloc")
print(Sales.iloc[-2:])
import pandas as pd
import numpy as np
import csv
df = pd.read_csv("student_result.csv")
print(df)
11. Given the school result data, analyses the performance of the students
on different parameters, e.g subject wise or class wise.
import pandas as pd
import matplotlib.pyplot as plt
subject = ['Physic','Chemistry','Mathematics', 'Biology','Computer']
marks =[80,75,70,78]
plt.plot(subject,marks,'green',marker ='*') # To draw line in red
colour
plt.title('Marks Scored') # To Write Title of the Line Chart
plt.xlabel('SUBJECT') # To Put Label At Y Axis
plt.ylabel('MARKS') # To Put Label At X Axis
plt.show()
12. Write a program to plot a bar chart in python to display the result of
a school for five consecutive years.
import matplotlib.pyplot as pl
year=['2015','2016','2017','2018','2019'] # list of years
p=[98.50,70.25,55.20,90.5,61.50] #list of pass percentage
j=['b','g','r','m','c'] # color code of bar charts
pl.bar(year, p, width=0.2, color=j)
pl.xlabel("year") # label for x-axis
pl.ylabel("Pass%") # label for y-axis
pl.show( ) # function to display bar chart
13. Plot the following data on a line chart and customize
the chart according to the below-given instructions:
14. Write a program to plot a range from 1 to 30 with step value 4. Use
following algebraic expression to show data.
y = 5*x+2
import matplotlib.pyplot as pp
import numpy as np
x = np.arange(1,30,4)
y=5*x+2
pp.plot(x,y)
pp.show()
15. Write python code to accept data of students and draw bar
chart.
import matplotlib.pyplot as pl
while(1):
print(" MENU")
print("1. Enter the data")
print("2. Plot the graph")
print("3. Exit")
ch=int(input("Enter the choice"))
if(ch==1):
n=int(input("Enter the number of students :"))
name=[]
mark=[]
for i in range(n):
n=input("Enter the name of the student :")
m=int(input("Enter the total marks :"))
name.append(n)
mark.append(m)
print(name)
print(mark)
elif(ch==2):
pl.bar(name,mark)
pl.grid()
pl.xlabel("Name")
pl.ylabel("Mark")
pl.title("Marks of student ")
pl.show()
elif(ch==3):
break
else:
print("Wrong choice")
SQL QUERIES
Answers:
[1] select * from movie ;
Output:
2. select distinct from a movie ;
4. select movie_id, movie name, production cost from movie where product
is >150000 and <1000000 ;
5. select movie name from movie where type =’action’ or type=’romance’ ;
Answers:
[1] select pow(5,3) ;
M1 2021/12 1 2 107 93
/20
M3 2021/12 1 3 86 81
/22
M4 2021/12 2 4 65 67
/23
M5 2021/12 1 4 52 88
/24
M6 2021/12 2 3 97 68
/25
Answers:
[1] create database sports
[2] Creating table with the given specification
desc team;
Inserting data: