Indira National School: Academic
Indira National School: Academic
WAKAD, PUNE
PRACTICAL FILE
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.
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.
__________________________________________________________________________________________________________________________
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
(ii) Modify the amount of section ‘A’ a as 76 and Section ‘C’ & ‘D’ as 70. Print the
changed object.
__________________________________________________________________________________________________________________________
section = ['A','B','C','D']
stud = [39,41,42,44]
#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’,
Write a Python program to Calculate and display income per capita for each of these
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:
A 6700
B 5600
C 5000
D 5200
Write a Python program to display which sections has made the contribution more
than 5500.
import pandas as pd
contriS= pd.Series(data=contri,index=['A','B','C','D'])
print('Charity contributions by each section:\n',contriS)
Output:
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.
import pandas as pd
days=
['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'
]
temperatures= [32,34.8,31,33.3,30.9,32.7,33]
print(temp)
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
Friday 32.7
Saturday 33.0
dtype: float64
_________________________________________________________________________
Program 6:
import pandas as pd
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])
avg1= t1.mean()
avg2= t2.mean()
avg3= t3.mean()
avg4= t4.mean()
a= [avg1,avg2,avg3,avg4]
avg= pd.Series(data=a)
#Displaying average temperature of the entire month
Output:
________________________________________________________________________
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 :
index=items)
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]]
Output:
item 1 3137
item 2 3436
item 3 4000
item 4 3682
item 5 4001
dtype: int64
_________________________________________________________________________
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.
import pandas as pd
rollnos= [1,2,3,4,5,6,7,8,9,10]
print('Final Marks:')
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:
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}
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)
#Displaying DataFrame
print(salesDf)
Output:
1 2
A NaN 54500.0
B NaN 51000.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
data [11,‘TV’,2,50000]
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
_________________________________________________________________________
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
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]
itemsDf= pd.DataFrame(items)
print(itemsDf)
del itemsDf1['Revenue']
itemsDf1= itemsDf1.drop(range(2,7,1))
itemsDf.rename(index={0:'aa',1:'bb',2:'cc',3:'dd',4:'ee',5:'ff',6:'gg',7
:'hh'},columns={'Item':'ITEM','Revenue':'REVENUE'})
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
Rows from 3 to 7:
Item Revenue
3 4 400
4 5 500
5 6 600
6 7 700
7 8 800
Item
0 1
1 2
7 8
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
import pandas as pd
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']
print(TempDf.iloc[::])
print(TempDf.loc[[‘Sunday’,’Tuesday’,’Thursday’,’Friday’])
________________________________________________________________________
Output:
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
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.
Output:
_________________________________________________________________________
Program 15:
Consider the following August month Vegetable Prices of Tomatoes, Onion, Potatoes
for four weeks.
as plt x=[1,2,3,4]
oni=[40,47,40,42]
tom=[50,45,49,35]
pota = [40,35,38,42]
plt.xlabel('Weeks')
plt.ylabel('Vegetable
price')
plt.title('August month Veg Price Analysis')
plt.legend()
plt.grid(True)
plt.show()
Output:
_________________________________________________________________________
Program 16:
weights= [ 78, 72, 69, 81, 63, 67, 65, 75, 79, 74, 71, 83, 71, 79, 80,
69]
#plotting histogram
plt.show()
plt.show()
plt.show()
plt.show()
Output:
_________________________________________________________________________
Program 17:
#Plotting histogram
plt.hist(x)
plt.show()
plt.hist([df['meters'],df['weight']],bins=20, histtype='barstacked',
orientation='horizontal')
plt.xlabel('meters')
plt.ylabel('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.
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])
_________________________________________________________________________
Program 19
cities = ['Delhi','Mumbai','Chennai','Banglore']
population = [23456756,22564534,28234578,21676567]
_________________________________________________________________________