0% found this document useful (0 votes)
249 views12 pages

Grade 12 - IP Practicals (1 To 9)

This document contains 9 practical exercises on data analysis using Pandas and Matplotlib libraries in Python. The practicals cover topics like creating series from dictionaries and arrays, filtering dataframes, plotting bar graphs and histograms to analyze data. Various functions of Pandas like read_csv(), to_csv(), groupby() and Matplotlib like bar(), hist() are used across the practicals to demonstrate data handling, aggregation and visualization. The final practical imports real-world census data and plots it for analysis and summary.

Uploaded by

Milan Laddha
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)
249 views12 pages

Grade 12 - IP Practicals (1 To 9)

This document contains 9 practical exercises on data analysis using Pandas and Matplotlib libraries in Python. The practicals cover topics like creating series from dictionaries and arrays, filtering dataframes, plotting bar graphs and histograms to analyze data. Various functions of Pandas like read_csv(), to_csv(), groupby() and Matplotlib like bar(), hist() are used across the practicals to demonstrate data handling, aggregation and visualization. The final practical imports real-world census data and plots it for analysis and summary.

Uploaded by

Milan Laddha
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/ 12

SNBP INTERNATIONAL SCHOOL & KIDZONE

SENIOR SECONDARY SCHOOL


MORWADI, PIMPRI, PUNE
CBSE AFFILIATION NO. 1130522
ACADEMIC YEAR 2021-2022

Informatics Practices

#Practical no 1
#Create a pandas series from a dictionary of values and an
ndarray
import pandas as pd
import numpy as np
students={"Harshil":10,"Sunny":10,"Sanya":12,"Shivani":13,"
ABC":14}
print("Original Dictionary")
print(students)
s1= pd.Series(students)
print("Series created from dictionary:")
print(s1)
arr=np.arange(6)
print("Array is:",arr)
s2=pd.Series(arr)
print("Series created from ndarray is :")
print(s2)
#Output
#Practical no 2
#Given a series, print all the elements that are above the
75th percentile.
import pandas as pd
import numpy as np
s=pd.Series(np.array([1,3,4,7,8,8,9]))
print(s)
res=s.quantile(q=0.75)
print()
print("75th percentile of the series is ::")
print(res)
print("The elements that are above the 75th percentile are:")
print(s[s>res])
#Output

#Practical no 3
#Create a Data Frame quarterly sales 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
quarterly_sales=dict()
quarterly_sale={ 'Item category': ['Cold
drink','Chips','Chocolate','Chips','Cold drink'],
'Item name':["Coke","Lays","Dairy
Milk","Kurkure","Spirit"],
'Expenditure':[35,20,40,20,65]}
df_sales=pd.DataFrame(quarterly_sale)
print("Original Dictionary:")
print(df_sales)
print()
print(df_sales.groupby("Item category").sum())

#Output

#Practical no 4
Create a data frame for examination result and display row
labels, column labels data types of each column and the
dimensions.
import pandas as pd
Dic={"Class":[ 1,2,3,4,5,6] , "Pass-
Percentage":[100,100,100,100,95,96]}
Result=pd.DataFrame(Dic)
print(Result)
print(Result.dtypes)
print("Shape of the dataframe:")
print(Result.shape)
#output

#Practical no 5
#Filter out rows based on different criteria such as duplicate
values.
import pandas as pd
dict1=
{'Name':['ABC1','XYZ1','ABC','XYZ4'],'Marks':[25,25,25,21]}
dmarks=pd.DataFrame(dict1)
print(dmarks)
DPRow=dmarks[dmarks.duplicated('Marks',keep='first')]
print(DPRow)
#Output

#Practical no 6
Importing and exporting data between pandas and CSV file
import pandas as pd
DF=pd.read_csv(“C:\\Python\\abc.csv”)
print(DF)
Output
Roll no Name
0 1201 abc
1 1202 xyz
2 1203 pqr
3 1204 lmn
4 1205 qwe
import pandas as pd
people={'Sales':{'name':'ABC','age':'24','Gender':'Male'} ,
'Marketing':{'name':'xyz','age':'22','Gender':'Female'}}
df1=pd.DataFrame(people)
print(df1)
df1.to_csv("C:\\Python\\abc.csv")
print()
#Output

#Practical no 7
#Given the school result data, analyse the performance of
the students on different parameters e.g subject wise or
class wise
import matplotlib.pyplot as plt
Subject=["Physics","Chemistry","Biology","Math",
"Informatics Practices"]
Percentage= [85,78,65,90,100]
plt.bar(Subject,Percentage,align="center",color="Green")
plt.xlabel("Subjects Name")
plt.ylabel("Pass Percentage")
plt.title("Bar Graph for result Analysis")
plt.show()
output

#Practical no 8
#For the DataFrame created above, analyze and plot
appropriate charts with title and legend.
import matplotlib.pyplot as plt
import numpy as np
s=["1st","2nd" ,"3rd"]
per_sc=[95,89,77]
per_com=[90,93,75]
per_hum=[97,92,77]
x=np.arange(len(s))
plt.bar(x,per_sc,label="Science",width=0.25,color="Green")
plt.bar(x+.25,per_com,label="Commerce",width=0.25,color="
red")
plt.bar(x+0.50,per_hum,label="Humanities",width=0.25,color
="gold")
plt.xlabel("Position")
plt.ylabel(" Percentage")
plt.title("Bar Graph for result Analysis")
plt.legend()
plt.show()
#Practical no 9
#Take data of your interest from an open source( eg:
data.gov.in), aggregate and summarize it. Then plot it using
different plotting functions of the Matplotlib library.
import pandas as pd
import matplotlib.pyplot as plt
DF=pd.read_csv("C:\\Python\\Census.csv")

slices=(DF["2019"].head(6))
states=(DF["State"].head(6))
#plt.plot(slices,states)
plt.title("2019 Census Data")
plt.ylabel("Cities")
plt.xlabel("Population")
#plt.bar(slices,states)
plt.hist(slices,bins=20,cumulative=True,histtype='barstacked',
orientation="vertical")
plt.show()

You might also like