National Public School: Name-Mohit Kumar Class-XII Subject - Informatics Practices (065) Board Roll No.
National Public School: Name-Mohit Kumar Class-XII Subject - Informatics Practices (065) Board Roll No.
National Public School: Name-Mohit Kumar Class-XII Subject - Informatics Practices (065) Board Roll No.
Practical file
Name- mohit kumar
Class-XII
Subject- Informatics Practices(065)
Board Roll No.-
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
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
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
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
df = pd.DataFrame(data)
df['Address'] = address
print(df)
output:-
Adding a row
Code:-
import pandas as pd
import numpy as np
NAME :- MOHIT KUMAR
print(df)
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
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
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
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
OUTPUT :-
NAME :- MOHIT KUMAR
Practical-18
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)
Output
NAME :- MOHIT KUMAR
Practical-21
Write a Program to Create a bar graph for result
analysis of 3 section
Output
NAME :- MOHIT KUMAR
Practical-22
Write a Program to Create a Bar Graph for
Visualization of Result
Output
\
NAME :- MOHIT KUMAR
Practical-23
Write a Program to Create a horizontal bar graph
for visualization Temp in different cities this
summer
Output
Practical-23
write a program to create histogram and
show the result.
CODE:-
OUTPUT:-
NAME :- MOHIT KUMAR