INFORMATICS PRACTICES
Practical File
Concept used: -Pandas, Matplotlib, SQL
SESSION: - 2022-2023
Class: - XII-G
Name: - Ayush Kumar
Lab Activity
Write a program in python to calculate the cube of the series values as given
- 2,5,7,4,9
Code:-
import pandas as pd #Importing pandas module
S_data = pd.Series([2,5,7,4,9])
print("Original Series data")
print(S_data)
print("Cube of Series data")
Cube_data= S_data**3
print(Cube_data)
Output: -
Lab Activity
Create a panda’s series from a dictionary of values and a Nd array
Code: -
import pandas as pd
import numpy as np
dict={
'pen':10,
'pencil':20,
'book':30,
'notebook':40
}
ser1=pd.Series(dict)
print('creating pandas series from dictionary')
print(ser1)
#usingnparray to create pandas series
arr = np.array([10,20,30,40])
ser2 = pd.Series(arr)
print('using nparray to create pandas series')
print(ser2)
Output: -
Lab Activity
Create a data frame for examination result and display row labels, column
labels data types of each column and the dimensions..
Code: -
import pandas as pd
marks={
'English': [96,86,49,85,73,62],
'Maths': [45,65,75,95,35,52],
'IP': [62,52,32,42,82,93],
'Sociology': [31,61,41,51,81,91],
'pol-science': [50,60,40,20,30,40]
}
result=pd.DataFrame(marks,index=['Vansh','Manan','Harman','Pushkar','Adit'
,'Ayush'])
print(result)
print('===============Name=============')
print(result.index)
print('============Subjects============')
print(result.columns)
print('====data types of each column====')
print(result.dtypes)
print('===========Dimension=============')
print(result.ndim)
Output: -
Lab Activity
Create a dataframe of marks and show five records from top and six records
from bottom
Code:-
import pandas as pd
dt={'English':[74,79,48,53,68,44,65,67],
'Physics':[76,78,80,76,73,55,49,60],
'Chemistry':[57,74,55,89,70,50,60,80],
'Biology':[76,85,63,68,59,79,49,69],
'IP':[82,93,69,98,79,88,77,66]}
df=pd.DataFrame(dt, index=[1201,1202,1203,1204,1205,1206,1207,1208])
print("===============All data from Dataframe================")
print(df)
print('=================5 records from top===============')
print(df.head(5))
print('=================5 records from bottom===============')
print(df.tail(6))
Output:-
Lab Activity
Given a Series, print all the elements that are above the 75th percentile.
Code:-
import pandas as pd
std_marks = [42, 12, 72, 85, 56, 100]
s = pd.Series(std_marks,index=[1201,1202,1203,1204,1205,1206])
print("the elements that are above the 75th percentile ")
print(s[s>=75])
Output: -
Lab Activity
Create a dataframe using list of tuples
Code:-
import pandas as pd
data =[
('Ayush',10,15),
('Vansh',20,25),
('Manan',30,35),
('Harman',40,45)
]
Column= ['Name','Age','Score']
dataframe=pd .DataFrame(data,columns=Column)
print(dataframe)
Output: -
Lab Activity
Write a programme to add column in dataframe
Code: -
import pandas as pd
data =[
('Ayush',10,15),
('Vansh',20,25),
('Manan',30,35),
('Harman',40,45)
]
Column= ['Name','Age','Score']
df=pd .DataFrame(data,columns=Column)
print('==========orignaldataframe==========')
print(df)
print('==========Adding column==========')
df2=df.assign(Class=[12,11,10,9])
print(df2)
Output:-
Lab Activity
Find the sum of each column, or find the column with the lowest mean.
Code: -
import pandas as pd
data = {
'a':[10,20,30,40],
'b':[2,4,6,8],
'c':[5,10,15,20]
}
df = pd.DataFrame(data)
print(df)
print('=======sum=========')
print(df.sum(axis=0))
print('=======mean========')
print(df.mean(axis=0))
Output: -
Lab Activity
Importing and exporting data between pandas and CSV file.
Code: -
import pandas as pd
import numpy as np
marks = {
"English" :[67,89,90,55],
"Maths":[55,67,45,56],
"IP":[66,78,89,90],
"Chemistry" :[45,56,67,65],
"Biology":[54,65,76,87]
}
result = pd.DataFrame(marks,index=["Harman","Manan","Vansh","Ayush"])
print('======Export result.csv======')
print("******************Marksheet****************")
print(result)
result.to_csv("result.csv")
df = pd.read_csv("result.csv")
print('======Import result.csv======')
print(df)
Output: -
Lab Activity
Given the school result data, analyses the performance of the students
ondifferent parameters, e.g subject wise or class wise.
Code: -
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
marks = { "English" :[67,89,90,55],
"Maths":[55,67,45,56],
"IP":[66,78,89,90],
"Chemistry" :[45,56,67,65],
"Biology":[54,65,76,87]}
df = pd.DataFrame(marks,index=['Harman','Manan','Vansh','Ayush'])
df.plot(kind='bar')
plt.show()
Output: -
Lab Activity
Create dataframe and analyse, and plot appropriate charts with title and
legend.
Code: -
import matplotlib.pyplot as plt
import numpy as np
s=['1st', '2nd', '3rd']
science=[95,89,77]
commerce=[90,93,75]
humanities=[97,92,77]
x=np.arange(len(s))
plt.bar(x,science, label='Science', width=0.15, color='blue')
plt.bar(x+.25,commerce,label=' commerce', width=0.15,color='red')
plt.bar(x+.50,humanities,label='Humanities', width=0.15, color='orange')
plt.xticks(x,s)
plt.xlabel('Position')
plt.ylabel('Percentage')
plt.title('Bar Graph For Result Analysis')
plt.legend()
plt.show()
Output:-
Lab Activity
Draw two line graph where x axis show the individual classes and the y axis
show no..of student paticipatingin Arts and computer inter house event
Code: -
import matplotlib.pyplot as p
x=[4,5,6,7]
y=[6,10,14,13]
z=[10,12,18,20]
p.plot(x,y,label="Student Participating in ART Comprtition")
p.plot(x,z,label="Student Participating in COMPUTER Comprtition")
p.legend()
p.title("My First Line Chart")
p.xlabel("Class")
p.ylabel("No.of Student participtaing")
p.grid(True)
p.show()
Output:-
Lab Activity
Create a Data frame with comparison of sales month wise also draw a bar
graph
Code: -
import matplotlib.pyplot as p
import pandas as pd
dict1={
'Mid_Car':[100,80,150,170],
'Bike':[150,155,170,180],
'High_Car':[50,60,70,40]
}
df=pd.DataFrame(dict1,index=['July','August','Sept','Oct'])
df.plot(kind='bar',color=['green','red','orange'])
p.title("Comparison of Sales Month Wise",fontsize=14,color='b')
p.xlabel("Month",fontsize=14,color='blue')
p.ylabel("Sales",fontsize=14,color='blue')
p.xticks(fontsize=10,rotation=30)
p.show()
Output: -
Lab Activity
Do a hobby analysis of student and create a pie chart
Code:-
import matplotlib.pyplot as p
l=["Music","Dance","Games","Drawing","Reading"]
Student=[130,150,180,160,75]
c=["red","green","yellow","blue","orange"]
expld=(0.1,0,0,0,0)
p.figure(figsize=[8,5])
p.title("Hobby Analysis")
p.pie(Student,explode=expld,labels=l,colors=c,autopct="%.2f%
%",shadow=True,startangle=(170))
p.show()
Output:-
Lab Activity
Write quires for following: -
1. Create a student table with the student id, name, and marks as
attributes where the student id is the primary key.
Query:-
create table student(student_id int(4) primary key,name
varchar(8),marks float(3,1));
2. Insert the details of a new student in the above table.
Query:-
insert into student values(6595,'Ayush',79.9);
3. Delete the details of a student in the above table.
Query:-
4. Use the select command to get the details of the students with marks
more than 80.
Query:-
select*from studentwhere marks>80;
5. Find the min, max, sum, and average of the marks in a student marks
table.
Query:-
Select min(marks) as minimum_marks,max(marks)
asmaximum_marks,sum(marks)astotal_marks,avg(marks)
asaverage_marksFrom student_marks ;
6. Find the total number of customers from each country in the table
(customer ID, customer Name, country) using group by.
Query:-
select country, count(country) from customers group by country;
7. Write a SQL
query to
order the
(student ID,
marks) table
in descending
order of the
marks.
Query:-
select student_id,marks from student order by marks desc;
Lab
Activity
1. Write an SQL query to fetch name from table in upper case
Query:-
Select upper(name) from student;
2. Write an SQL query to print marks for Student with the first name as
Vansh and Manan from Worker table.
Query:-
Select name,marks from student where name='vansh' or
name='manan';