[go: up one dir, main page]

0% found this document useful (0 votes)
421 views55 pages

Indira National School: Academic

The document provides details of Krish Vanvari's practical file for the academic year 2022-2023 at Indira National School in Wakad, Pune. It includes a list of 17 programs completed with their dates of programming and submission. The file also includes certificates of completion for the practical component of the Informatics Practices subject for CBSE examinations.

Uploaded by

Krish Vanvari
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)
421 views55 pages

Indira National School: Academic

The document provides details of Krish Vanvari's practical file for the academic year 2022-2023 at Indira National School in Wakad, Pune. It includes a list of 17 programs completed with their dates of programming and submission. The file also includes certificates of completion for the practical component of the Informatics Practices subject for CBSE examinations.

Uploaded by

Krish Vanvari
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/ 55

INDIRA NATIONAL SCHOOL

WAKAD, PUNE

ACADEMIC YEAR 2022-2023

PRACTICAL FILE

Name: Krish Vanvari


CBSE Roll Number:
Class: XII Science Alpha
Exam: AISSCE
INDEX
S.No Program Statement Date of Date of Sign
Program Submission
1 Write a Python program to create a Series object 29-Jun- 30-Jun-
that stores the contribution amount as the values 2022 2022
and the
Section names are the indexes.
2 Create the following a series object that stores the 05-Jul-2022 06-Jul-
number of students in each section [‘A’,’B’,’C’,’D’] of 2022
class 12 and do as directed.
3 Population Series stores the population of details of 12-Jul-2022 13-Jul-
four metro cities [‘Delhi’,’Mumbai’,’Kolkata’,’Chennai’] 2022
of our country and Average income details are given.
Write a Python program to Calculate and display
income per capita
for each of these cities along with both the series
objects
4 Series s stores the charity contribution made by each 13-Jul-2022 14-Jul-
section Write a Python program to display which 2022
sections
has made the contribution more than 5500
5 Write a python code to create a Series object Temp 16-Jul-2022 17-Jul-
that stores temperatures of seven days in it. Its index 2022
should be ‘Sunday’, ‘Monday’, ’Saturday’
Display first two days temperature and last two days
temperature.
6 Series objects t1, t2, t3, t4 stores temperatures of 20-Jul-2022 21-Jul-
weeks week1, week2, week3, week4 respectively. Write 2022
a Python program to print
a) Average temperature per week.
b)Average temp of entire month
7 Write a program that stores the sales of 5 fast moving 02-Aug- 03-Aug-
items of a store for each month in 12 Series objects, 2022 2022
i.e., S1 Series object stores sales of these 5 items in 1st
month, S2 stores sales of these 5 items in 2nd month,
and so on
The program should display the summary sales report
8 Three Series objects stores the marks of 10 students 08-Aug- 09-Aug-
in three terms. Roll numbers of students form the 2022 2022
index of these Series objects. The Three Series
objects have the same indexes. Write a Python
program to Calculate and display 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 and display the series object.
9 Create a DataFrame df using the given 10-Aug- 12-Aug-
dictionaries Write Python code to 2022 2022
i) List the index labels of the DataFrame df
ii) List the column names of the Datframe df
iii) Print the Dataframe df
10 Create a Dataframe df that has 10 rows in it and has 15-Aug- 16-Aug-
columns as ‘Item’, ‘Qty’, ‘Price’. You can choose to put 2022 2022
any values of your choice. Write code for the given
statements
11 Write a Python program create dataframe namely sales 17-Aug- 18-Aug-
having ‘Item’ and ‘Revenue’ as columns.. 2022 2022
write code for the given statements

12 Four series objects Temp1, Temp2, Temp3 and Temp4 22-Aug- 23-Aug-
store the temperatures of week1, week2, week3 and 2022 2022
week4 respectively. Write a Python program to create
a dataframe from these four series objects where the
indexes should be ‘Sunday’, ‘Monday’, … , ‘Saturday’,
and columns should be ‘Week1’, ‘Week2’, ‘Week3’ and
‘Week4’. Write code to calculate and display as given.
13 Marks of 5 23-Aug- 24-Aug-
students['Nisha','Thomas','Shubhi','Keya','John'] in four 2022 2022
unit tests ['UT1','UT2','UT3','UT4'] stored in Dataframe
student. Write a Python program to create student
DataFrame and write code as given.
14 Write a program to input Item name and Sales 25-Aug- 26-Aug-
made in a dataframe salesDF and then store this 2022 2022
data in a CSV file.
15 Consider the following August month Vegetable Prices 30-Aug- 31-Aug-
of Tomatoes,Onion,Potatoes for four weeks. Draw a line 2022 2022
chart
to analyze the prices of vegetables.

16 Given the following set of data : 01-Sep- 02-Sep-


Weight measurement for 16 small orders of 2022 2022
french fries(in grams)
[ 78, 72, 69, 81, 63, 67, 65, 75, 79, 74, 71, 83, 71, 79,
80, 69]
Create a simple histogram from the above data.Set
x and y-axis labels,Title.
a) Create a horizontal histogram from the above
data.
b) Create step type of histogram from the above
data
c) Create a cumulative histogram from the above
data
17 Given a Dataframe as given below. 06-Sep- 07-Sep-
import pandas as pd 2022 2022
import matplotlib.pyplot as plt x={'speed':
[10,15,20,18,19],'meters':[122,159,190,230,300],
'weight':[0.2,0.3,0.1,0.85,0.0]}
df=pd.DataFrame (x)
Write code to create the following plots.
a) Create a normal histogram
b) Create stacked ,horizontal histogram with
meters and weight
c) Give axis labels and title for the plot
18 Consider Commonwealth Games 2018‘s medal count 08-Sep- 09-Sep-
for four countries of Gold, Silver ,Bronze and Total are 2022 2022
as follows
Aust = [80,59,59,198]
India = [26,20,20]
England = [45,45,46,136]
Canada = [15,40,27,82]
Medal type = [‘Gold’, ‘Silver’ ,’Bronze’,’Total’]

● Draw a Bar chart for the same


● Set x & y axis labels
● Set the Title
● Set the legend
19 Consider the population of four major cities given as 15-Sep- 16-Sep-
follows. 2022 2022
cities = ['Delhi','Mumbai','Chennai','Banglore']
population =
[23456756,22564534,28234578,21676567]
● Draw a Bar chart
● Set the width,color of the bars
● Set x & y axis labels
● Set the Title.
● Set the legend.
Draw Horizontal Bar chart for the same..
Indira National School, Pune
Certificate

This is to certify that Master/Miss ___________ studying in

Indira National School, Pune of Class XII Science Alpha

CBSE Examination Number: ___________________________________

Has satisfactorily performed the practicals in Informatics

Practices subject as laid down by the CBSE Board during the

Academic Year 2022 – 2023.

________________ ________________ _______________

Principal’s External Internal


Signature Examiner Examiner

Date: School Stamp:


Program 1:
A Python list namely section stores the section names (‘A’,’B’,’C’,’D’) of class 12 in
your school. Another list contri stores the contribution made by these students to a
charity fund endorsed by the school as [6000,5000,8000,4000].

Write a Python program to create a Series object that stores the contribution amount
as the values and the section names are the indexes.

Your school has decided to double the contribution. Write code for this considering
datatype as float for contri.
__________________________________________________________________________________________________________________________

#Program to print donation Series.

import pandas as pd

section = ['A','B','C','D']
contri=[6000,5000,8000,4000]
s = pd.Series (data = contri,index=section)
print(‘Original Series:\n’,s)
ar = np.array(contri) # creating numpy array
s = pd.Series (data = ar*2,index=section,dtype='float')
print(‘Series after School contribution:\n’,s)
__________________________________________________________________________________________________________________________

Output:
Original Series:
A 6000
B 5000
C 8000
D 4000
Series after School
contribution:
A 12000.0
B 10000.0
C 16000.0
D 8000.0

dtype: float64
__________________________________________________________________________________________________________________________
Program 2:
Create the following a series object that stores the number of students in each section
[‘A’,’B’,’C’,’D’] of class 12 as follows
A 39

B 41

C 42

D 44

First two sections have been given the task of selling tickets @ 100/- per ticket as part
of social experiment. Write code to

(i) Display how much they have collected?

(ii) Modify the amount of section ‘A’ a as 76 and Section ‘C’ & ‘D’ as 70. Print the

changed object.
__________________________________________________________________________________________________________________________

# Program to operate on Series object


import pandas as pd

section = ['A','B','C','D']
stud = [39,41,42,44]

#Creating the Series


x = pd.Series(stud, index = section)
print('Original Series')
print(x)

#Sum Collected
print('Sum collected =',x.sum())

#Updated Series
x['A']=76
x['C']=s['D']=70
print('Updated Series')
print(x)
__________________________________________________________________________________________________________________________

Output:
Original Series:
A 6000
B 5000
C 8000
D 4000
Series after School
contribution:
A 12000.0
B 10000.0
C 16000.0
D 8000.0

dtype: float64
__________________________________________________________________________________________________________________________
Program 3:
Population Series stores the population of details of four metro cities [‘Delhi’,’Mumbai’,

’Kolkata’,’Chennai’] of our country as popu = [10897689, 12875653, 4678452, 4378788].

AverageIncome Series stores the average income details [721324589787898,

89678985678967, 879876789678956, 5645789876453432] of four metro cities.

Write a Python program to Calculate and display income per capita for each of these

cities along with both the series objects.

# Program calculate per capita income of given cities.


import pandas as pd

#Creating Series with population of cities as


data
cities=['Delhi','Mumbai','Kolkatta','Chennai']
popu = [10897689,12875653,4678452,4378788]
PopulationS = pd.Series(data=popu,index=cities) print('Population:\
n',PopulationS)

#Creating Series with average income of cities as data


avgincome=[721324589787898,89678985678967,879876789678956,564578987645343
2]
AverageIncomeS = pd.Series(data=avgincome,index=cities)
print('Average Income:\n',AverageIncomeS)

#Calculating per capita income.


PCIncomeS = AverageIncomeS/PopulationS
print('Per Capita Income:\n',PCIncomeS)

Output:
Population:
Delhi 10897689
Mumbai 12875653
Kolkatta 4678452
Chennai 4378788
dtype: int64
Average Income:
Delhi 721324589787898
Mumbai 89678985678967
Kolkatta 879876789678956
Chennai 5645789876453432
dtype: int64
Per Capita Income:
Delhi 6.619060e+07
Mumbai 6.965005e+06
Kolkatta 1.880701e+08
Chennai 1.289350e+09
dtype:float64
________________________________________________________________________
Program 4:

Series s stores the charity contribution made by each section as follows

A 6700

B 5600

C 5000

D 5200

Write a Python program to display which sections has made the contribution more
than 5500.

#Program to display sections which made contribution more than given


amount

import pandas as pd

#Creating Series with contributions made by each section as data


contri=[6700,5600,5000,5200]

contriS= pd.Series(data=contri,index=['A','B','C','D'])
print('Charity contributions by each section:\n',contriS)

#Displaying sections which made contribution more than 5500


print('Sections that contributed more than 5500:')
print(contriS[contriS>5500])

Output:

Charity contributions by each


section: A 6700

B 5600

C 5000

D 5200

dtype: int64
Sections that contributed more than
5500: A 6700

B 5600

dtype: int64

_________________________________________________________________________
Program 5:

Write a python code to create a Series object Temp that stores temperatures of
seven days in it. Its index should be ‘Sunday’, Monday……..’Saturday’

Display first two days temperature and last two days temperature.

# Program to print first two and last elements from Series

import pandas as pd

#Creating the Series

days=
['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'
]

temperatures= [32,34.8,31,33.3,30.9,32.7,33]

temp= pd.Series(data=temperatures, index=days)

print(temp)

#Displaying temperature of first two days

print('Temperature of first two days:\n',temp.head(2))

#Displaying temperature of last two days

print('Temperature of last two days:\n',temp.tail(2))

Output:

Sunday 32.0

Monday 34.8

Tuesday 31.0

Wednesday 33.3

Thursday 30.9

Friday 32.7

Saturday 33.0

dtype: float64
Temperature of first two days:

Sunday 32.0

Monday 34.8

dtype: float64

Temperature of last two days:

Friday 32.7

Saturday 33.0

dtype: float64
_________________________________________________________________________
Program 6:

Series objects t1,t2,t3,t4 stores temperatures of weeks week1,week2,week3,week4


respectively. Write a Python program to print

A) Average temperature per week.

B) Average temp of entire month

#Program to calculate average from data of Series

import pandas as pd

#Creating Series(4 weeks with temperatures of 7 days)

t1= pd.Series([31,30.7,32,32.5,31.3,32.8,30])

t2= pd.Series([33.5,32,33.1,34,32.9,31.7,31.2])

t3= pd.Series([31.8,31,33.6,34.8,34.1,35,34.8])

t4= pd.Series([32.9,33.3,35,34.5,33,32.3,32])

#Displaying average temperatures of each week

avg1= t1.mean()

print('Average temperature of week 1 is',avg1)

avg2= t2.mean()

print('Average temperature of week 2 is',avg2)

avg3= t3.mean()

print('Average temperature of week 3 is',avg3)

avg4= t4.mean()

print('Average temperature of week 4 is',avg4)

#Creating series from list of average temperatures of 4 weeks

a= [avg1,avg2,avg3,avg4]

avg= pd.Series(data=a)
#Displaying average temperature of the entire month

print('Average temperature of the month is',avg.mean())

Output:

Average temperature of week 1 is 31.47142857142857

Average temperature of week 2 is 32.628571428571426

Average temperature of week 3 is 33.58571428571428

Average temperature of week 4 is 33.285714285714285

Average temperature of the month is 32.74285714285714

________________________________________________________________________
Program 7:

Write a program that stores the sales of 5 fast moving items of a store for each month
in 12 Series objects, i.e., S1 Series object stores sales of these 5 items in 1st month, S2
stores sales of these 5 items in 2nd month, and so on

The program should display the summary sales report like this :
Total Yearly Sales, item-wise (should display sum of items’ sales over the
months) Maximum sales of item made :
Maximum sales for individual items
Maximum sales of item 1 made :
Maximum sales of item 2 made :
Maximum sales of item 3 made :
Maximum sales of item 4 made :
Maximum sales of item 5 made :

#Program to display yearly sales and maximum sales item

wise #Creating Series(12 months with data of sales of 5

items) s1= pd.Series(data=[100,132,250,327,370],

index=items)

s2= pd.Series(data=[421,386,333,301,450], index=items)

s3= pd.Series(data=[240,380,392,201,199], index=items)

s4= pd.Series(data=[150,196,226,298,173], index=items)

s5= pd.Series(data=[265,212,342,300,419], index=items)

s6= pd.Series(data=[189,290,377,209,417], index=items)

s7= pd.Series(data=[346,393,404,449,440], index=items)

s8= pd.Series(data=[122,141,306,275,195], index=items)

s9= pd.Series(data=[200,274,480,433,457], index=items)

s10= pd.Series(data=[312,382,283,209,251], index=items)

s11= pd.Series(data=[407,431,500,492,369], index=items)

s12= pd.Series(data=[385,219,107,188,261], index=items)

#Calculating total yearly sales


sum= s1+s2+s3+s4+s5+s6+s7+s8+s9+s10+s11+s12

print('Total Yearly Sales:\n',sum)

print('Maximum sales of item made is:',sum.idxmax())

# Creating lists with objects from index 0 to 4 from Series


l1=
[s1[0],s2[0],s3[0],s4[0],s5[0],s6[0],s7[0],s8[0],s9[0],s10[0],s11[0],s1
2 [0]]

l2=
[s1[1],s2[1],s3[1],s4[1],s5[1],s6[1],s7[1],s8[1],s9[1],s10[1],s11[1],s1
2 [1]]

l3=
[s1[2],s2[2],s3[2],s4[2],s5[2],s6[2],s7[2],s8[2],s9[2],s10[2],s11[2],s1
2 [2]]

l4=
[s1[3],s2[3],s3[3],s4[3],s5[3],s6[3],s7[3],s8[3],s9[3],s10[3],s11[3],s1
2 [3]]

l5=
[s1[4],s2[4],s3[4],s4[4],s5[4],s6[4],s7[4],s8[4],s9[4],s10[4],s11[4],s1
2 [4]]

#Displaying maximum sales of each item

print('Maximum sales for individual items:')

print('Maximum sales of item 1 made:',max(l1))

print('Maximum sales of item 2 made:',max(l2))

print('Maximum sales of item 3 made:',max(l3))

print('Maximum sales of item 4 made:',max(l4))

print('Maximum sales of item 5 made:',max(l5))

Output:

Total Yearly Sales:

item 1 3137
item 2 3436
item 3 4000

item 4 3682

item 5 4001

dtype: int64

Maximum sales of item made is: item 5

Maximum sales for individual items:

Maximum sales of item 1 made: 421

Maximum sales of item 2 made: 431

Maximum sales of item 3 made: 500

Maximum sales of item 4 made: 492

Maximum sales of item 5 made: 457

_________________________________________________________________________
Program 8:

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. Write a Python program to Calculate and display 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 and display the series object.

#Program to display marks of students

import pandas as pd

rollnos= [1,2,3,4,5,6,7,8,9,10]

#Creating Series(3 terms with marks of 10 students)

term1= pd.Series([71,69,66,78.5,72,60.5,54,77,70.5,71], index=rollnos)

term2= pd.Series([70.5,78,78,74,73.5,67,70,78.5,68.5,66], index=rollnos)

term3= pd.Series([78,69.5,64,72,79.5,63,79,73.5,76,68.5], index=rollnos)

#Calculating and displaying marks of each student

print('Final Marks:')

finalmarks= ((1/4)*term1) + ((1/4)*term2) + ((1/2)*term3)

print(finalmarks)

Output:

Final Marks:

1 74.375

2 71.500

3 68.000

4 74.125
5 76.125

6 63.375

7 70.500

8 75.625

9 72.750

10 68.500
dtype: float64

_________________________________________________________________________
Program 9:

Create a DataFrame sales using the following dictionaries

yr1={'Qtr1':44900,'Qtr2':46100,'Qtr3':57000,'Qtr4':59000}

yr2={'Qtr1':35000,'Qtr2':36100,'Qtr3':37000,'Qtr4':39000}

yr3={'Qtr1':55500,'Qtr2':56100,'Qtr3':57000,'Qtr4':54000}

disales={2001:yr1,2002:yr2,2003:yr3}

Write Python code to

i) List the index labels of the DataFrame sales

ii) List the column names of the DataFrame sales

iii) Print the DataFrame df

#Program to create DataFrame from given data

import pandas as pd

#Creating DataFrame

yr1={'Qtr1':44900,'Qtr2':46100,'Q3':57000,'Q4':59000}

yr2={'A':54500,'B':51000,'Qtr4':57000}

disales={1:yr1,2:yr2}

salesDf= pd.DataFrame(disales)

#Listing index labels of DataFrame

print('Index labels are:\n', salesDf.index)

#Listing column names of DataFrame

print('Column names are:\n', salesDf.columns)

#Displaying DataFrame
print(salesDf)

Output:

Index labels are:

Index(['Qtr1', 'Qtr2', 'Q3', 'Q4', 'A', 'B', 'Qtr4'], dtype='object')

Column names are:

Index([1, 2], dtype='int64')

1 2

Qtr1 44900.0 NaN

Qtr2 46100.0 NaN

Qtr3 57000.0 NaN

Qtr4 59000.0 NaN

A NaN 54500.0

B NaN 51000.0

Qtr4 NaN 57000.0

_________________________________________________________________________
Program 10:

Create a DataFrame myShop that has 10 rows in it and has columns as ‘ItemName’,
‘Qty’, ‘Price’. You can choose to put any values of your choice.
Write Python code to

A) Display only column ‘qty’

B) Display only rows 0 and 1 with all the columns.

C) Display only column ‘Qty’ and ‘Price’ and row 1 to 5

D) Add a new column ‘ItemId’ as 1st column.

E) Add a new row with the following

data [11,‘TV’,2,50000]

#Program to perform operations on DataFrame having data of items in shop


import pandas as pd

#Creating DataFrame with details of items as data


import pandas as pd
i1={'Item':'AC', 'Qty':3, 'Price':75000}
i2={'Item':'Refrigerator', 'Qty':1, 'Price':68000}
i3={'Item':'Computer', 'Qty':4, 'Price':200000}
i4={'Item':'Laptop', 'Qty':3, 'Price':150000}
i5={'Item':'Juicer', 'Qty':1, 'Price':9500}
i6={'Item':'Keyboard', 'Qty':5, 'Price':40000}
i7={'Item':'WebCam', 'Qty':2, 'Price':6000}
i8={'Item':'Stylus', 'Qty':3, 'Price':75000}
i9={'Item':'Charger', 'Qty':5, 'Price':2500}
i10={'Item':'Iron','Qty':1,
'Price':9500}
items=[i1,i2,i3,i4,i5,i6,i7,i8,i9,i10]
myShop= pd.DataFrame(items)
print('Item details:\n',myShop)

#Displaying column 'Qty'


print('Column Qty:\n', myShop.Qty)

#Displaying rows 0 and 1


print('Rows with index 0 and 1:\n', myShop.loc[0:1])

#Displaying columns 'Qty' and 'Price' and rows from 1 to 5


print('Columns Qty and Price and rows from 1 to 5:\n',
myShop.iloc[1:6,1:3])

#Adding a new column 'ItemId'


myShop.insert(0,'ItemId',[1,2,3,4,5,6,7,8,9,10])

#Adding a new row


myShop.at[10,:]=[11,'TV',2,50000
]
print('Updated DataFrame:\n', myShop)

Output:
Item details:
Item Qty Price
0 AC 3 75000
1 Refrigerator 1 68000
2 Computer 4 200000
3 Laptop 3 150000
4 Juicer 1 9500
5 Keyboard 5 40000
6 WebCam 2 6000
7 Stylus 3 75000
8 Charger 5 2500
9 Iron 1 9500

Column Qty:
0 3
1 1
2 4
3 3
4 1
5 5
6 2
7 3
8 5
9 1
Name: Qty, dtype: int64

Rows with index 0 and 1:


Item Qty Price
0 AC 3 75000
1 Refrigerator 1 68000

Columns Qty and Price and rows from 1 to


5: Qty Price
1 1 68000
2 4 200000
3 3 150000
4 1 9500
5 5 40000
Updated DataFrame:
ItemId Item Qty Price
0 1.0 AC 3.0 75000.0
1 2.0 Refrigerator 1.0 68000.0
2 3.0 Computer 4.0 200000.0
3 4.0 Laptop 3.0 150000.0
4 5.0 Juicer 1.0 9500.0
5 6.0 Keyboard 5.0 40000.0
6 7.0 WebCam 2.0 6000.0
7 8.0 Stylus 3.0 75000.0
8 9.0 Charger 5.0 2500.0
9 10.0 Iron 1.0 9500.0
10 11.0 TV 2.0 50000.0

_________________________________________________________________________
Program 11:

Write a Python program create DataFrame namely sales having ‘Item’ and ‘Revenue’
as columns.

Item Revenue

0 1 100

1 2 200

2 3 300

3 4 400

4 5 500

5 6 600

6 7 700

7 8 800

And write code to do the following.

(a) Display the DataFrame

(b) List only columns ‘Item’ and ‘Revenue’

(c) List rows from 3 to 7.

(d) List the value of cell in 5th row, ‘Item’ column.

e) Remove a column ‘Revenue’

f) Remove 2-6 Rows from DataFrame.

g) Rename the index to ‘aa’,’bb’,’cc’ and so on.

h) Rename the columns to ‘ITEM’ and ‘REVENUE’

#Program to create DataFrame from given data and perform operations on


it

import pandas as pd

item1= {'Item':1,'Revenue':100}
item2=

{'Item':2,'Revenue':200}

item3=

{'Item':3,'Revenue':300}

item4=

{'Item':4,'Revenue':400}

item5=

{'Item':5,'Revenue':500}

item6=

{'Item':6,'Revenue':600}

item7=

{'Item':7,'Revenue':700}

item8=

{'Item':8,'Revenue':800}

items= [item1,item2,item3,item4,item5,item6,item7,item8]

#Creating and displaying the DataFrame

itemsDf= pd.DataFrame(items)

print(itemsDf)

#Displaying columns 'Item' and 'Revenue'

print('Columns Item and Revenue:\n', itemsDf.columns)

#Displaying rows from 3 to 7

print('Rows from 3 to 7:\n', itemsDf.loc[3:8])

#Displaying value Cell in 5th row of 'Item' column

print('5th row, Item column:\n', itemsDf.Item[4])


#Removing column 'Revenue' and rows from 2 to 6

itemsDf1= pd.DataFrame(itemsDf) #creating a copy of DataFrame

del itemsDf1['Revenue']

itemsDf1= itemsDf1.drop(range(2,7,1))

print('DataFrame with deleted rows and columns:\n',itemsDf1)


#Renaming index to aa,bb,cc... and columns to 'ITEM' and 'REVENUE'

itemsDf.rename(index={0:'aa',1:'bb',2:'cc',3:'dd',4:'ee',5:'ff',6:'gg',7
:'hh'},columns={'Item':'ITEM','Revenue':'REVENUE'})

print('DataFrame with renamed index and columns:\n', itemsDf)

Output:

Item Revenue

0 1 100

1 2 200

2 3 300

3 4 400

4 5 500

5 6 600

6 7 700

7 8 800

Columns Item and Revenue:


Index(['Item', 'Revenue'], dtype='object')

Rows from 3 to 7:

Item Revenue
3 4 400
4 5 500
5 6 600
6 7 700
7 8 800

5th row, Item Column:


5
DataFrame with deleted rows and columns

Item

0 1

1 2

7 8

DataFrame with renamed index and columns:

Item Revenue

0 1 100

1 2 200

2 3 300

3 4 400

4 5 500

5 6 600

6 7 700

7 8 800

_________________________________________________________________________
Program 12:

Four series objects Temp1, Temp2, Temp3 and Temp4 store the temperatures of
week1, week2, week3 and week4 respectively. Write a Python program to create a
DataFrame from these four series objects where the indexes should be ‘Sunday’,
‘Monday’, … , ‘Saturday’, and columns should be ‘Week1’, ‘Week2’, ‘Week3’ and
‘Week4’. write code to calculate and display the following

a) Fetch and display entire DataFrame (Using loc & iloc).


b) Fetch and display Sunday, Tuesday, Thursday, Friday all four weeks data
(Using loc and iloc)
c) Fetch and display Sunday to Thursday all week2 and week 3 data (Using loc
& iloc).

#Program to create DataFrame with data of temperatures of 4 weeks

import pandas as pd

#creating DataFrame with temperatures of 4 weeks

Temp1= pd.Series([31,30.7,32,32.5,31.3,32.8,30])

Temp2= pd.Series([33.5,32,33.1,34,32.9,31.7,31.2])

Temp3= pd.Series([31.8,31,33.6,34.8,34.1,35,34.8])

Temp4= pd.Series([32.9,33.3,35,34.5,33,32.3,32])

Temp={'Week1':Temp1,'Week2':Temp2,'Week3':Temp3,'Week4':Temp4}

TempDf= pd.DataFrame(Temp)

TempDf.index=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday
','Saturday']

#Printing entire DataFrame

print(TempDf.iloc[::])

#Displaying temperatures of Sunday,Tuesday,Thursday and Friday

print(TempDf.loc[[‘Sunday’,’Tuesday’,’Thursday’,’Friday’])

________________________________________________________________________
Output:

Week1 Week2 Week3 Week4

Sunday 31.0 33.5 31.8 32.9

Monday 30.7 32.0 31.0 33.3

Tuesday 32.0 33.1 33.6 35.0

Wednesday 32.5 34.0 34.8 34.5

Thursday 31.3 32.9 34.1 33.0

Friday 32.8 31.7 35.0 32.3

Saturday 30.0 31.2 34.8 32.0

Week1 Week2 Week3 Week4


Sunday 31.0 33.5 31.8 32.9

Tuesday 32.0 33.1 33.6 35.0

Thursday 31.3 32.9 34.1 33.0

Friday 32.8 31.7 35.0 32.3


________________________________________________________________________
Program 13:

Marks of 5 students ['Nisha','Thomas','Shubhi','Keya','John'] in four unit tests


['UT1','UT2','UT3','UT4'] stored in DataFrame student. Write a Python program to
create student DataFrame and write code for the following.

a) Print Student wise data from the DataFrame

b) Print Unit Test wise data from the DataFrame.

#Program to print marks of students from DataFrame


import pandas as pd
#Creating the DataFrame
n= {'UT1':37.5,'UT2':35,'UT3':38,'UT4':37}
t= {'UT1':30,'UT2':34.5,'UT3':32,'UT4':29.5}
s= {'UT1':35,'UT2':30.5,'UT3':34,'UT4':31.5}
k= {'UT1':29,'UT2':31,'UT3':27,'UT4':28.5}
j= {'UT1':38,'UT2':36.5,'UT3':40,'UT4':39.5}
marks= [n,t,s,k,j]
studentDf= pd.DataFrame(marks,
index=['Nisha','Thomas','Shubhi','Keya','John'])

#Printing student wise


data print('Student wise
data:')
for a,b in studentDf.iterrows():
print(a)
print(b)

#Printing Unit test wise


data print('Unit test wise
data')
for a,b in
studentDf.iteritems():
print(a)
print(b)

Output:

Student wise
data:
Nisha
UT1 37.5
UT2 35.0
UT3 38.0
UT4 37.0
Name: Nisha, dtype:
float64
Thomas
UT1 30.0
UT2 34.5
UT3 32.0
UT4 29.5
Name: Thomas, dtype:
float64
Shubhi
UT1 35.0
UT2 30.5
UT3 34.0
UT4 31.5
Name: Shubhi, dtype:
float64
Keya
UT1 29.0
UT2 31.0
UT3 27.0
UT4 28.5
Name: Keya, dtype: float64
John
UT1 38.0
UT2 36.5
UT3 40.0
UT4 39.5
Name: John, dtype: float64

Unit test wise data


UT1
Nisha 37.5
Thomas 30.0
Shubhi 35.0
Keya 29.0
John 38.0
Name: UT1, dtype: float64

UT2
Nisha 35.0
Thomas 34.5
Shubhi 30.5
Keya 31.0
John 36.5
Name: UT2, dtype: float64

UT3
Nisha 38
Thomas 32
Shubhi 34
Keya 27
John 40
Name: UT3, dtype: int64

UT4
Nisha 37
Thomas 29.5
Shubhi 31.5
Keya 28.5
John 39.5
Name: UT2, dtype: float64
________________________________________________________________________________________________________
Program 14:

Write a program to input Item name and Sales made in a DataFrame salesDF and then
store this data in a CSV file.

Write a program to read data from CSV file created in the above program.

#Program to store and read data from CSV file


import pandas as pd
#Creating DataFrame items={'item1':[180,200,150,210],'item2':
[205,245,190,165],'item3':[150, 135,190,195],'item4':[200,195,260,245]}
salesDF= pd.DataFrame(items)

#Storing data in CSV file


salesDF.to_csv('Item and Sales CSV.csv', index=False)

#Reading data from the created CSV file


salesDF1= pd.read_csv('Item and Sales CSV.csv')
print(salesDF1)

Output:

item1 item2 item3 item4


0 180 205 150 200
1 200 245 135 195
2 150 190 190 260
3 210 165 195 245

_________________________________________________________________________
Program 15:

Consider the following August month Vegetable Prices of Tomatoes, Onion, Potatoes
for four weeks.

x=[1,2,3,4] # For four weeks


oni=[40,47,40,42]
tom=[50,45,49,35]
pota = [40,35,38,42]
● Draw a line chart to analyze the prices of vegetables.
● Set the X-axis label as Weeks
● Set the Y-axis label as Vegetable price
● Set the title as 'August month Veg Price Analysis'
● Label the lines as Onions, Tomatoes, Potatoes
● Set the marker type, size and color.
● Show the grid

#Program to plot vegetable

prices import matplotlib.pyplot

as plt x=[1,2,3,4]

oni=[40,47,40,42]

tom=[50,45,49,35]

pota = [40,35,38,42]

#Plotting line chart

plt.plot(x,oni, color='magenta', markersize=8, linewidth=5,


linestyle='solid', label='Onions')

plt.plot(x,tom, color='red', markersize=8, linewidth=5,


linestyle='dotted', label='Tomatoes')

plt.plot(x,pota, color='yellow', markersize=8, linewidth=5,


linestyle='dashed', label='Potatoes')

plt.xlabel('Weeks')

plt.ylabel('Vegetable

price')
plt.title('August month Veg Price Analysis')

plt.legend()

plt.grid(True)

plt.show()

Output:

_________________________________________________________________________
Program 16:

Given the following set of data:


Weight measurement for 16 small orders of french fries(in
grams) [ 78, 72, 69, 81, 63, 67, 65, 75, 79, 74, 71, 83, 71, 79, 80, 69]
Create a simple histogram from the above data. Set x and y-axis labels, title.
a) Create a horizontal histogram from the above data.
b) Create step type of histogram from the above data
c) Create a cumulative histogram from the above data

#Program to plot data of weights of orders of french fries

import matplotlib.pyplot as plt

weights= [ 78, 72, 69, 81, 63, 67, 65, 75, 79, 74, 71, 83, 71, 79, 80,
69]

#plotting histogram

plt.hist(weights, bins=10, color='yellow')

plt.xlabel('weight of french fries(in grams)')

plt.title('Weight measurement for 16 small orders of french fries(in


grams)')

plt.show()

#Plotting horizontal histogram

plt.hist(weights, bins=10,orientation='horizontal', color='yellow')

plt.ylabel('weight of french fries(in grams)')

plt.title('Weight measurement for 16 small orders of french fries(in


grams)')

plt.show()

#Plotting step type histogram

plt.hist(weights, histtype='step', color='yellow')


plt.xlabel('weight of french fries(in grams)')

plt.title('Weight measurement for 16 small orders of french fries(in


grams)')

plt.show()

#plotting cumulative histogram

plt.hist(weights, histtype='step', cumulative=True, color='yellow')

plt.xlabel('weight of french fries(in grams)')

plt.title('Weight measurement for 16 small orders of french fries(in


grams)')

plt.show()

Output:
_________________________________________________________________________
Program 17:

Given a DataFrame as given below.


import pandas as pd
import matplotlib.pyplot as plt x={'speed':
[10,15,20,18,19],'meters':[122,159,190,230,300],
'weight':[0.2,0.3,0.1,0.85,0.0]}
df=pd.DataFrame (x)
Write code to create the following plots.
a) Create a normal histogram
b) Create stacked, horizontal histogram with meters and weight
c) Give axis labels and title for the plot

#Program to plot histograms from given data


import pandas as pd
import matplotlib.pyplot as plt x={'speed':[10,15,20,18,19],'meters':
[122,159,190,230,300],
'weight':[0.2,0.3,0.1,0.85,0.0]}
df=pd.DataFrame (x)

#Plotting histogram
plt.hist(x)
plt.show()

#Plotting horizontal barstacked histogram

plt.hist([df['meters'],df['weight']],bins=20, histtype='barstacked',
orientation='horizontal')

plt.xlabel('meters')

plt.ylabel('weights')

plt.title('meters and weights')

plt.show()
Output:

________________________________________________________________________
Program 18:

Consider Commonwealth Games 2018‘s medal count for four countries of Gold, Silver,
Bronze and Total are as follows…
Aust = [80,59,59,198]
India = [26,20,20]
England = [45,45,46,136]
Canada = [15,40,27,82]
Medal_type = [‘Gold’, ‘Silver’,’Bronze’,’Total’]
● Draw a Bar chart for the same
● Set x & y axis labels
● Set the Title.
● Set the legend.

#Program to plot data of different medals won in Commonwealth


Games import numpy as np
import matplotlib.pyplot as plt

Aust = [80,59,59,198]
India = [26,20,20,21]
England = [45,45,46,136]
Canada = [15,40,27,82]
Medal_type = ['Gold','Silver','Bronze','Total']

x = np.array([0,1,2,3])

plt.bar(Medal_type,Aust,width = 0.15,color = 'lightgreen',label =


'Australia')
plt.bar(x+0.15,India,width = 0.15,color = 'orange',label =
'India') plt.bar(x+0.3,England,width = 0.15,color =
'lightblue',label = 'England')
plt.bar(x+0.45,Canada,width = 0.15,color = 'pink',label = 'Canada')
plt.xlabel('Medal Type')
plt.ylabel('Medals')
plt.title('Medals won')
plt.legend()
plt.show()
Output:

_________________________________________________________________________
Program 19

Consider the population of four major cities given as follows.


cities = ['Delhi','Mumbai','Chennai','Bangalore']
population = [23456756,22564534,28234578,21676567]
● Draw a Bar chart
● Set the width, color of the bars
● Set x & y axis labels
● Set the Title.
● Set the legend.
● Draw Horizontal Bar chart for the same.

#Program to plot bar chart from given data


import matplotlib.pyplot as plt
import numpy as np

cities = ['Delhi','Mumbai','Chennai','Banglore']
population = [23456756,22564534,28234578,21676567]

#Plotting bar chart


plt.bar(cities,population,width = 0.5,color =
['yellow','green','deeppink','black'],label = cities)
plt.xlabel('Cities')
plt.ylabel('Population')
plt.legend()
plt.show()

#Plotting horizontal bar chart


plt.barh(cities,population,height = 0.5,color =
['yellow','green','deeppink','black'],label = cities)
plt.xlabel('Cities')
plt.ylabel('Population')
plt.legend()
plt.show()
Output:

_________________________________________________________________________

You might also like