0% found this document useful (0 votes)
2K views19 pages

Final Class 12 Commerce Practical File

This document contains a practical report on Informatics Practices submitted by a Class 12 student. It includes 12 coding problems and solutions related to data handling and visualization using Pandas and Matplotlib Python libraries. The problems cover topics like creating and manipulating Pandas Series and DataFrames, importing/exporting CSV data, filtering rows, aggregating and plotting data. Visualizations include bar plots and performance analysis plots on subject-wise and district-wise data.

Uploaded by

Snehil Chundawat
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)
2K views19 pages

Final Class 12 Commerce Practical File

This document contains a practical report on Informatics Practices submitted by a Class 12 student. It includes 12 coding problems and solutions related to data handling and visualization using Pandas and Matplotlib Python libraries. The problems cover topics like creating and manipulating Pandas Series and DataFrames, importing/exporting CSV data, filtering rows, aggregating and plotting data. Visualizations include bar plots and performance analysis plots on subject-wise and district-wise data.

Uploaded by

Snehil Chundawat
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/ 19

A

PRACTICAL REPORT
ON
Informatics Practices
Class: XII
SUBJECT CODE: 065
2021-22

SUBMITTED BY SUBMITTED TO
NAME: Mrs. Sangeetha D
CLASS: XII (Computer Teacher)
Stream: Commerce

SUBMISSION DATE

1
DATA HANDLING
1. Create a pandas series from a dictionary of values and an ndarray
a. Using Dictionary
Coding:
import pandas as pd
items={"Pencil":10,"Pen":25,"Eraser":50,"Scale":30,"Crayons":25}
series1=pd.Series(items)
print("Series Object using dictionary is:")
print(series1)
Output:

2
b. Using ndarray
Coding:
import pandas as pd
importnumpy as np
items=np.array([10,25,50,30,25])
series2=pd.Series(items,index=["Pencil","Pen","Eraser","Scale","Crayons
"])
print("Series using ndarray:")
print(series2)
Output:

3
2. Write a program to perform mathematical operation on two Pandas series
object
Coding:
import pandas as pd
s1 = pd.Series([22,44,66,88,100])
s2 = pd.Series([11,22,33,44,55])
addition = s1+s2
print("Addition of two Series object:")
print(addition)
substraction = s1-s2
print("Subtraction of two Series object:")
print(substraction)
multiply = s1*s2
print("Product of two Series object:")
print(multiply)
division = s1/s2
print("Division of two Series object:")
print(division)
Output:

4
3. Given a Series, print all the elements that are above the 75th
percentile.
Coding:
import pandas as pd
importnumpy as np
array1=np.array([10,5,85,66,95,46,78,85,63,6])
series1=pd.Series(array1)
q1=series1.quantile(q=0.75)
print("75th Quantile is:",q1)
print("Values which are greater than 75th percentile")
print(series1[series1>q1])

Output:

5
4. 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.
Coding:
Import numpy as np
import pandas as pd
salesdata={"Item Category":
["Food","Drink","Food","Drink","Sweets","Food","Sweets"], "Item
Name":
["Biscuit","Pepsi","Bread","Mrinda","Chocolate","Namkeen","Milkmaid"
], "Expenditure":[100,30,80,250,80,220,300]}
Sales_Quaterly=pd.DataFrame(salesdata)
print(Sales_Quaterly)
category=Sales_Quaterly.groupby("Item Category")
print(category.groups)
te=category['Expenditure'].sum()
print(te)

Output:

6
5. Create a data frame for examination result and display row labels,
column labels data types of each column and the dimensions.
Coding:
import pandas as pd
dict={'Class':['I','II','III','IV','V','VI','VII','VIII','IX','X','XI','XII'],
'Pass-Percentage':[100,100,100,100,100,100,100,100,100,98.6,100,99]}
r=pd.DataFrame(dict)
print("Results of examination:")
print(r)
print(r.dtypes)
print('Shape od the dataframe is:')
print(r.shape)

Output:

7
6. Filter out rows based on different criteria such as duplicate rows.
Coding:
import pandas as pd
dict={'Name':['Amit','Deepika','Pavan','Devesh','Geeta','Pavan','Geeta',
'rohan'],
'Totalmarks':[65,75,85,56,98,85,98,45]}
t=pd.DataFrame(dict)
print("Data Frame:")
print(t)
dr=t[t.duplicated()]
print("Duplicated Row in given data frame:")
print(dr)

Output:

8
7. Importing and exporting data between pandas and CSV file
Coding:
import pandas as pd
d=pd.read_csv("C:\\Users\\abc\\Desktop\\Item_Sale.csv")
print(d)

Output:

9
8. Write a program to generate a series of 10 numbers with a scalar
value of 44.
Coding:

import pandas as pd
print(pd.Series(44,range(1,11)))

Output:

10
9. Create a dataframe and iterate them over rows
Coding:

import pandas as pd
data = [["Ram",55,66,31],["Sam",88,66,43],[
"Ravi",99,101,68]]
players = pd.DataFrame(data,
columns = ["Name","Match-1","Match-2","Match-3"])
print("Iterating by rows:")
for index, row in players.iterrows():
print(index, row.values)
print("Iterating by columns:")
for index, row in players.iterrows():
print(index, row["Name"],row["Match-1"],
row["Match-2"],row["Match-3"])
Output:

11
10. Create a dataframe and print it along with their index using iteritems().
Coding:

import pandas as pd
sc_4yrs={2016:{'Virat Kohli':2595,'Rohit Sharma':2406,'Shikhar
Dhawan':2378},
2017:{'Virat Kohli':2818,'Rohit Sharma':2613,'Shikhar Dhawan':2295},
2018:{'Virat Kohli':2735,'Rohit Sharma':2406,'Shikhar Dhawan':2378},
2019:{'Virat Kohli':2455,'Rohit Sharma':2310,'Shikhar Dhawan':1844}}
df=pd.DataFrame(sc_4yrs)

for (year,runs) in df.iteritems():


print("Year:",year)
print(runs)
Output:

12
11. Write a pandas program to select rows where score is between 15 and 20.
Coding:

import pandas as pd
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],
"score" :[12.6,20,16.7,19]}
result = pd.DataFrame(marks,index=["Athang","Sujata","Sushil","Sumedh"])
print("******************Marksheet****************")
print(result)
print("Rows where score between 15 and 20 (inclusive):")
print(result[result['score'].between(15, 20)])
Output:

13
12. Write a Pandas program to select rows where score is missing i.e. NaN.

Coding:

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],
"score" :[12.6,np.nan,16.7,np.nan]}
result = pd.DataFrame(marks,index=["Athang","Sujata","Sushil","Sumedh"])
print("******************Marksheet****************")
print(result)
print("Rows where score is missing:")
print(result[result['score'].isnull()])
Output:

14
VISUALIZATION
13. Given the school result data, analyse the performance of the
students on different parameters, e.gsubject wise or class wise.
Coding:
importmatplotlib.pyplot as pt
subject=['BST','IT','Economics','English','Accounts']
p=[85,78,65,90,100]
pt.bar(subject,p,align='center',color='green')
pt.xlabel('Subject Name')
pt.ylabel('Pass Percent')
pt.title('Bar Graph for result analysis')
pt.show()

Output:

15
14. For the Data frames created above, analyze and plot appropriate
charts with title and legend.
Coding:
importmatplotlib.pyplot as pt
importnumpy 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))
pt.bar(x,per_sc,label='Science',width=0.25,color='green')
pt.bar(x+.25,per_com,label='commerce',width=0.25,color='red')
pt.bar(x+.50,per_hum,label='Humanities',width=0.25,color='gold')
pt.xticks(x,s)
pt.xlabel('Position')
pt.ylabel('Percentage')
pt.title('Bar Graph For Result Analysis')
pt.legend()
pt.show()

16
Output:

17
15. Take data of your interest from an open source (e.g. data.gov.in),
aggregate and summarize it. Then Plot it using different plotting
functions of the Matplotlib library.
Coding:
import pandas as pd
importmatplotlib.pyplot as pl
d=pd.read_csv("C:\\Users\\abc\\Desktop\\hmis.csv")
print(d)
y=(d['Performance - Overall Average '])
x=(d['District'])
pl.figure(figsize=(10,20))
pl.bar(x,y,color="Cyan",width=0.25)
pl.xlabel("District")
pl.ylabel("Performance-Overall Average")
pl.title("HMIS District Overall Performance")
pl.show()

18
Output:
Data taken from data.gov.in:

19

You might also like