You are on page 1of 24

NAME :- KARAN CHOUDHARY

National Public School

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

Submitted To- Mr. Manish Kumar


NAME :- KARAN CHOUDHARY

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
03. Write a program to show the attributes of a series
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 menu based program to perform the following
operations on columns of the above defined dataframe
based on user specified inputs: (a) Insert a new column at
the end (b)Insert a new column at a specified position (c)
Delete a column permanantly (d)Delete a column
temporarily (e) Display the dataframe
13. create the dataframe sales containing year wise sales
NAME :- KARAN CHOUDHARY

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
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)
NAME :- KARAN CHOUDHARY

OUTPUT:-

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 :- KARAN CHOUDHARY

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 :- KARAN CHOUDHARY

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 :- KARAN CHOUDHARY

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 :- KARAN CHOUDHARY

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 :- KARAN CHOUDHARY

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 :- KARAN CHOUDHARY

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 :- KARAN CHOUDHARY

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 :- KARAN CHOUDHARY

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 :- KARAN CHOUDHARY

• 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 :- KARAN CHOUDHARY

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
• 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
NAME :- KARAN CHOUDHARY

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']
dic={'2014':inr2014,'2015':inr2015,'2016':inr2016,'2017':inr2017}
Sales = pd.DataFrame(dic,index=label)
print(Sales)

output:-

Practical-13
• 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]]
NAME :- KARAN CHOUDHARY

df = pd.DataFrame(player_list, columns=['Name', 'Age', 'Weight',


'Salary'])
print(df)
df1 = df.iloc[0:4]
print(df1)
output:-

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 :- KARAN CHOUDHARY

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 :- KARAN CHOUDHARY

Practical-14
• 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 :- KARAN CHOUDHARY

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 :- KARAN CHOUDHARY

Practical-15
• 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 :- KARAN CHOUDHARY

Practical-16
• 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 :- KARAN CHOUDHARY

Practical-17

• 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 :- KARAN CHOUDHARY

COPING TO NEWCOPY.CSV
NAME :- KARAN CHOUDHARY

You might also like