You are on page 1of 35

NAME :- MOHIT KUMAR

National Public School

Practical file
Name- mohit kumar
Class-XII
Subject- Informatics Practices(065)
Board Roll No.-

Submitted To- Mr. Manish Kumar


NAME :- MOHIT KUMAR

INDEX
Sno Title Remark
.
01. Write a program to create series from two list
02. Write a program to create series using ndarry and
dictionary
Write a program to show the attributes of a series
03.
04. Write a program to create two series S1 and S2 Write a
Python program to add, subtract, multiple and divide two
Pandas Series
05. Three Series objects stores the marks of 10 students in three
terms. Roll numbers of students form the index of these
Series objects. The Three Series objects have the same
indexes. Calculate the total weighted marks obtained by
students as per following formula : Final marks = 25%
Term 1 + 25% Term 2 + 50% Term 3 Store the Final marks
of students in another Series object
06. Write a program to show the methods(head(),count(),tail())
of a series.
07. Write a program to generate a series of 5 elements of
multiples of 7 starting with 35 with index multiply by 3.
08. Write a program to create datafram from dictionay of list
and list of dictionary.
09. Write a program to display use of various attribute of data
frame.
10. Write a program to create a dataframe of the class and
accept the roll number of the child ( given as index) from
the user and display all his details. The program must
continue executing till the user wants. The program must
give a valid output if the roll number entered for searching
is not there in the dataframe
11. Write a program to Add column and row in existing Data
frame
12. Write a code to add row in existing data frame

13. create the dataframe sales containing year wise sales


figures for five sales person in INR .use the years as column
label and sales person name as row labels.
14. write a program to create dataframe and represent
NAME :- MOHIT KUMAR

indexing and slicing.


15. Write a program to Sort Data in Data Frame

16. Write a Program to Create a DataFrame by importing a


csv() file
17. Write A program to create a student CSV file from
DataFrame
18. Write a program to create a CSV file by coping the contents
of Book1.csv
19. Write a Program to Create a Cricket Match representation
using Bar Graph
20. Write a Program to Create a Representation of passing
percentage of three section over years (Line Chart)

21. Write a Program to Create a bar graph for result analysis


of 3 section

22. Write a Program to Create a Bar Graph for Visualization


of Result
23. Write a Program to Create a horizontal bar graph for
visualization Temp in different cities this summer
24. write a program to create histogram and show the result.

Practical-1
 Write a program to create series from two list.
CODE:- imprt pandas a pd
1st = [1,2,3,4,5,6]
S = pd.series(1st)
Print(s)

OUTPUT:-
NAME :- MOHIT KUMAR

Practical-2
 Write a program to create series using ndarray and
dictionary.
Code:-
Import pandas as pd
Dct = {‘A’:4, ‘b’:4,’c’:3,’d’:0,’E’:5}
S = pd.series(dct)
Print(s)
Output:-
NAME :- MOHIT KUMAR

Practical-3
 Write a program to show the attributes of a series.
CODE:-
Import pandas as pd
Sr = pd.series([‘INDIA’,’AUSTRALIA’,’ENGLAND’,’RUSIA’,’AFRICA’])
Se.index = [‘COUNTRAY
1’,’COUNTRY2’,’COUNTRY3’,’COUNTRY4,’COUNTRY5’]
print(sr)
OUTPUT:-
NAME :- MOHIT KUMAR

Practical-4
 Write a program to create two series S1 and S2 Write a
Python program to add, subtract, multiple and divide
two Pandas Series.
CODE:-
import pandas as pd
ds1 = pd.Series([2, 4, 6, 8, 10])
ds2 = pd.Series([1, 3, 5, 7, 9])
ds = ds1 + ds2
print("Add two Series:")
print(ds)
print("Subtract two Series:")
ds = ds1 - ds2
print(ds)
NAME :- MOHIT KUMAR

print("Multiply two Series:")


ds = ds1 * ds2
print(ds)
print("Divide Series1 by Series2:")
ds = ds1 / ds2
print(ds)
OUTPUT:-

Practical-5
 Three Series objects stores the marks of 10 students in three terms.
Roll numbers of students form the index of these Series objects. The
Three Series objects have the same indexes. Calculate the total
weighted marks obtained by students as per following formula : Final
NAME :- MOHIT KUMAR

marks = 25% Term 1 + 25% Term 2 + 50% Term 3 Store the Final
marks of students in another Series object.
CODE:- import pandas as pd
roll = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
T1 = pd.Series([98, 75, 99, 100, 95, 64, 33, 76, 79, 80], index=roll)
T2 = pd.Series([84, 89, 69, 89, 90, 90, 65, 60, 72, 100], index=roll)
T3 = pd.Series([89, 73, 79, 70, 92, 99, 93, 86, 98, 85], index=roll)
FM = pd.Series(0.25*T1 + 0.25*T2 + 0.5*T3) # Finl Marks series
print(FM)
OUTPUT:-

Practical-6
 Write a program to show the methods(head(),count(),tail()) of a series .
CODE :- import pandas as pd
import numpy as np
data = np.array(['1', '2', '4', '8', '10', '12'])
NAME :- MOHIT KUMAR

ser = pd.Series(data)
print(ser)
print(ser.head(2))
print(ser.tail())
print(ser.count())
OUTPUT :-

Practical-7
 Write a program to generate a series of 5 elements of multiples
of 7 starting with 35 with index multiply by 3.
NAME :- MOHIT KUMAR

CODE :- import pandas as pd


import numpy as np
a=35
n = np.arange(a,a*2,7)
s = pd.Series(index=n*3,data=n)
print(s)
OUTPUT:-

DATA FRAME.

Practical-8
 Write a program to create data frame from dictionary of list and
list of dictionary.
CODE :- import pandas as pd
dict = {'name':["aparna", "pankaj", "sudhir", "Geeku"],
'degree': ["Mohit", "raj", "karan", "any one"],
'score':[80, 60, 80, 98]}
df = pd.DataFrame(dict)
print (df)
NAME :- MOHIT KUMAR

output :-

Practical-9
 Write a program to display use of various attribute of data
frame.
Example #1: Use DataFrame.values attribute to return the numpy
representation of the given DataFrame.
CODE :- import pandas as pd
Import numpy as np
Dict = {“first score”:[100, 90, np.nan, 95],
“second score”: [30, 45, 56, np.nan],
“third score” :[np.nan, 40, 80, 98]}
Df = pd.dataframe(dict)
Df.fillna(0)
Print(df)
output:-
NAME :- MOHIT KUMAR

Practical-10
 Write a program to create a dataframe of the class and accept
the roll number of the child ( given as index) from the user and
display all his details. The program must continue executing till
the user wants. The program must give a valid output if the roll
number entered for searching is not there in the dataframe
CODE:- import pandas as pd
import numpy as np
exam_data = {‘name’ : [‘raj’ , ’karan’ , ’mohit’ , ’nishant’ , ’nemat’ ,
’ganesh’ , ’abinash’ , ’harsh’ , ’kiru’ , ’dev’],
‘score’ : [12.5, 9, 16.5, np.nam, 9, 20, 14.5, np.nam, 8, 19],
‘attemts’ : [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
‘qualify’: [‘yes’, ‘no’, ‘yes’, ‘no’, ‘no’, ‘yes’, ‘yes’, ‘no’, ‘no’, ‘yes’]}

Rollno = [‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘10’]
Df = pd.dataframe(exam_data , index=rollno)
Print (df)
Output:-

Practical-11
NAME :- MOHIT KUMAR

 Write a program to Add column in existing data


frame.
CODE :-
import pandas as pd

data = {'Name': ['raj', 'mohit', 'karan', 'Anuj'],


'Height': [5.1, 6.2, 5.1, 5.2],
'Qualification': ['Msc', 'MA', 'Msc', 'Msc']}

df = pd.DataFrame(data)

address = ['Delhi', 'mumbai', 'uttarpradesh', 'uttrakhand']

df['Address'] = address

print(df)
output:-

Adding a row
Code:-
import pandas as pd
import numpy as np
NAME :- MOHIT KUMAR

dict = {'Name':['Martha', 'Tim', 'Rob', 'Georgia'],


'Maths':[87, 91, 97, 95],
'Science':[83, 99, 84, 76] }
df = pd.DataFrame(dict)

print(df)

df2 = {'Name': 'Amy', 'Maths': 89, 'Science': 93}


df = df.append(df2, ignore_index = True)

print(df)
Output:-

Practical-12
 Write a code to add row in existing data frame.
CODE:-
import pandas as pd
from numpy.random import randint
NAME :- MOHIT KUMAR

dict = {'Name':['Martha', 'Tim', 'Rob', 'Georgia'],


'Maths':[87, 91, 97, 95],
'Science':[83, 99, 84, 76]}
df = pd.DataFrame(dict)
print(df)
df.loc[len(df.index)] = ['Amy', 89, 93]
print(df)

OUTPUT :-

Practical-13
 create the dataframe sales containing year wise sales figures
for five sales person in INR .use the years as column label and
sales person name as row labels.
Code:-
import pandas as pd
inr2014=[700,2100,1300,878,987]
inr2015=[700,2100,1310,878,978]
inr2016=[5000,2100,1350,878,977]
inr2017=[700,2150,1370,878,987]

label=['Mohit','Karan','Kumar','Anuj','suraj']
NAME :- MOHIT KUMAR

dic={'2014':inr2014,'2015':inr2015,'2016':inr2016,'2017':inr2017}
Sales = pd.DataFrame(dic,index=label)
print(Sales)

output:-

Practical-14
 write a program to create dataframe and represent
indexing and slicing.
a. Slicing row CODE :-
import pandas as pd
player_list = [['virat koli', 36, 75, 5428000],
['j. root', 38, 74, 3428000],
['V.Kholi', 31, 70, 8428000],
['S.Suraya', 34, 80, 4428000],
['C.Gayle', 40, 100, 4528000],
['J.ben', 33, 72, 7028000],
['K.Pet', 42, 85, 2528000]]
df = pd.DataFrame(player_list, columns=['Name', 'Age', 'Weight',
'Salary'])
print(df)
df1 = df.iloc[0:4]
print(df1)
output:-
NAME :- MOHIT KUMAR

b. Slicing column CODE :-


import pandas as pd
player_list = [['M.S.Dhoni', 36, 75, 5428000],
['A.B.D Villers', 38, 74, 3428000],
['V.Kholi', 31, 70, 8428000],
['S.Smith', 34, 80, 4428000],
['C.Gayle', 40, 100, 4528000],
['J.Root', 33, 72, 7028000],
['K.Peterson', 42, 85, 2528000]]
df = pd.DataFrame(player_list, columns=['Name', 'Age', 'Weight',
'Salary'])
print(df)
df1 = df.iloc[:,0:2]
print(df1)

output:-
NAME :- MOHIT KUMAR

C. INDEXING.
CODE :-
import pandas as pd
player_list = [['M.S.Dhoni', 36, 75, 5428000],
['A.B.D Villers', 38, 74, 3428000],
['V.Kholi', 31, 70, 8428000],
['S.Smith', 34, 80, 4428000],
['C.Gayle', 40, 100, 4528000],
['J.Root', 33, 72, 7028000],
['K.Peterson', 42, 85, 2528000]]
df = pd.DataFrame(player_list, columns=['Name', 'Age', 'Weight', 'Salary'],
index=['A', 'B', 'C', 'D', 'E', 'F', 'G'])
print(df)
OUTPUT:-
NAME :- MOHIT KUMAR

Practical-15
 Write a program to Sort Data in Data Frame.
CODE :-
import pandas as pd
age_list = [['Afghanistan',1952,8425333,'Asia'],
['Australia',1957,9712569,'Oceania'],
['Brazil',1962,76039390,'Americas'],
['China',1957,637408000,'Asia'],
['France',1957,44310863,'Europe'],
['India',1952,3.72e+08,'Asia'],
['United States',1957,171984000,'Americas']]
df = pd.DataFrame(age_list,columns=['Country','Year','Population','Continent'])
df.sort_values(by=['Country'])
print(df)

OUTPUT:-
NAME :- MOHIT KUMAR

A. Sorting the Data frame in Descending order.


CODE :-
import pandas as pd
age_list = [['Afghanistan', 1952, 8425333, 'Asia'],
['Australia', 1957, 9712569, 'Oceania'],
['Brazil', 1962, 76039390, 'Americas'],
['China', 1957, 637408000, 'Asia'],
['France', 1957, 44310863, 'Europe'],
['India', 1952, 3.72e+08, 'Asia'],
['United States', 1957, 171984000, 'Americas']]
df=pd.DataFrame(age_list,columns=['Country',
'Year','Population', 'Continent'])
df.sort_values(by=['Population'], ascending=False)
Output:-
NAME :- MOHIT KUMAR

Practical-16
 Write a Program to Create a DataFrame by importing a csv()
file
CODE :-

import pandas as pd
df = pd.read_csv("C:\\Users\\ANSHU\\Desktop\\ip project\\bd.csv",
encoding = 'latin1')
pd.set_option('max_columns',None)
pd.set_option('max_rows',None)
print(df.head())

OUTPUT:-
NAME :- MOHIT KUMAR

Practical-17
 Write A program to create a student CSV file from
DataFrame.
CODE :- import pandas as pd

name = ["aparna", "pankaj", "sudhir", "Geeku"]


deg = ["MBA", "BCA", "M.Tech", "MBA"]
scr = [90, 40, 80, 98]
dict = {'name': nme, 'degree': deg, 'score': scr}
df = pd.DataFrame(dict)
df.to_csv('STUDENTS.csv')

OUTPUT :-
NAME :- MOHIT KUMAR

Practical-18

 Write a program to create a CSV file by coping the contents


of Book1.csv
CODE :-

import csv
with open(r'C:\Users\karan\Desktop\ip project\karan\newcopy.csv', 'w') as
csvfile:
filewriter = csv.writer(csvfile)
with open(r'C:\Users\karan\Desktop\ip project\karan\book1.csv', 'r') as
infile:
filereader = csv.reader(infile)
for row in filereader:
filewriter.writerow(row)
OUTPUT :- (COPING ALL DATA FROM BOOK1.CSV TO NEWCOPY.CSV)
NAME :- MOHIT KUMAR

COPING TO NEWCOPY.CSV
NAME :- MOHIT KUMAR

Practical-19
 Write a Program to Create a Cricket Match
representation using Bar Graph
Input
#Bar Graph for Representaion of Cricket Match between India
and Australia
import matplotlib.pyplot as plt
import numpy as np

a=[50,60,70,80,90]
NAME :- MOHIT KUMAR

b=[55,65,60,75,96]
x=np.linspace(1,51,5)
plt.bar(x,a,width=3,color='r',label='Australia')
plt.bar(x+3,b,width=3,color='g',label='India')
plt.xlabel('Overs')
plt.ylabel('Run Scored')
plt.title('Scoring Chart')
plt.legend()
plt.show()

Output
NAME :- MOHIT KUMAR

Practical-20
 Write a Program to Create a Representation of
passing percentage of three section over years
(Line Chart)

# Creating a line chart for representation of passing


percentage of three section over years
import matplotlib.pyplot as plt
import numpy as np
year=[2015,2016,2017,2018,2019]
Science=[97,99,98,95,96]
Commerce=[99,98,92,96,95]
Humanities=[94,96,98,92,90]
plt.plot(year,Science,color='g')
plt.plot(year,Commerce,color='orange')
plt.plot(year,Humanities,color='r')
plt.xlabel('Year')
plt.ylabel('Passing Percentage')
plt.title('Passing Percentage Record Class XII')
plt.show()
NAME :- MOHIT KUMAR

Output
NAME :- MOHIT KUMAR

Practical-21
 Write a Program to Create a bar graph for result
analysis of 3 section

#Crating Bar Graph for Result Anaysis of 3 Streams


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='r
ed')
plt.bar(x+.50,per_hum,label='Humanities',width=0.25,color='
gold')
plt.xticks(x,s)
plt.xlabel('Position')
plt.ylabel('Percentage')
plt.title('Bar Graph For Result Anaysis')
plt.legend()
plt.show()
NAME :- MOHIT KUMAR

Output
NAME :- MOHIT KUMAR

Practical-22
 Write a Program to Create a Bar Graph for
Visualization of Result

#Creating Bar Graph for Visualisation of Result


import matplotlib.pyplot as plt
subject=['Physics','Chemistry','Mathematics','Biology','IP']
Percentage=[85,78,65,90,100]
plt.bar(subject,Percentage,align='center',color='green')
plt.xlabel('SUBJECT NAME')
plt.ylabel('PASS PERCENTAGE')
plt.title('Bar Graph for Result Anaysis')
plt.show()

Output

\
NAME :- MOHIT KUMAR

Practical-23
 Write a Program to Create a horizontal bar graph
for visualization Temp in different cities this
summer

import matplotlib.pyplot as plt


import numpy as np
Cities=['Kanpur','Lucknow','Delhi','Prayagraj','Varanasi']
Temp=[42,39,48,46,40]
plt.barh(Cities,Temp)
plt.xlabel('Temperature')
plt.ylabel('Cities')
plt.title('City-Wise Temperature Record')
plt.show()
NAME :- MOHIT KUMAR

Output

Practical-23
 write a program to create histogram and
show the result.
CODE:-

from matplotlib import pyplot as plt


import numpy as np
a = np.array([22, 87, 5, 43, 56,
73, 55, 54, 11,
20, 51, 5, 79, 31,
27])
fig, ax = plt.subplots(figsize =(10, 7))
NAME :- MOHIT KUMAR

ax.hist(a, bins = [0, 25, 50, 75, 100])


plt.show()

OUTPUT:-
NAME :- MOHIT KUMAR

You might also like