0% found this document useful (0 votes)
51 views

Ip Project

This document contains a practical report submitted by a student named Karm Parmar from Green Valley High School. The report contains examples of using pandas to create and manipulate series and dataframes. It includes examples of creating series from lists, performing operations on series like sorting, filtering, and aggregating. It also includes examples of creating dataframes from dictionaries, adding and removing columns, and performing operations like finding maximum values. The report contains 21 examples in total along with questions and their outputs.

Uploaded by

Karm Parmar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Ip Project

This document contains a practical report submitted by a student named Karm Parmar from Green Valley High School. The report contains examples of using pandas to create and manipulate series and dataframes. It includes examples of creating series from lists, performing operations on series like sorting, filtering, and aggregating. It also includes examples of creating dataframes from dictionaries, adding and removing columns, and performing operations like finding maximum values. The report contains 21 examples in total along with questions and their outputs.

Uploaded by

Karm Parmar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 27

AMPAD, VADODARA

GUJARAT

ACADEMIC YEAR [2021-22]

PRACTICAL REPORT (065)

INFORMATICS
PRACTICES
In partial fulfillment of the requirement
of
AISSCE (CBSE)
By
Name:Karm Parmar
Grade:12THD Science
Roll No.: 12148
Under the Supervision of
Mrs. Shobha S. Rudragoudar
PGT – Informatics Practices
H.O.D. – Computer Department

GREEN VALLEY HIGH SCHOOL


INDEX

SR.NO DATE EXAMPLE/QUESTIONS PG.NO


1 20/6/2021 11,12
2 21/6/2021 13,19,20
3 22/6/2021 33,40,41
4 23/6/2021 6,7,12
5 24/6/2021 33,38
6 25/6/2021 42,43
7 26/6/2021 44,14
8 27/6/2021 15,16
9 28/6/2021 4,7
10 29/6/2021 19,23,25,26
11 30/6/2021 4,5
12 1/7/2021 7,9
13 2/7/2021 12,13
14 3/7/2021 14,16
15 4/7/2021 17,19,20
16 5/7/2021 22,24
17 6/7/2021 29,3
18 7/7/2021 21,27
19 8/7/2021 30,31
20 9/7/2021 32,10
21 10/7/2021 11,12

EXAMPLE 11.
INPUT:
import pandas as pd
section = ['A', 'B', 'C', 'D', 'E']
contribution = [5000, 6000, 6500, 7500, 8000
ser = pd.Series(data = contribution, index = section)

print(ser)
OUTPUT
A 5000
B 6000
C 6500
D 7500
E 8000
dtype: int64

EXAMPLE 12.

INPUT
import pandas as pd
import numpy as np
idx=[ 'A','B','C','D','E']
contr=[8900,8700,7800,6500,None]
s1=pd.Series(data=contr, index=idx,dtype=np.float32)
print("Donation by each secion : Rs.")
print(s1)
print("Donation after the amount is doubled: Rs.")
print(s1*2)
OUTPUT
A 17800.0
B 17400.0
C 15600.0
D 13000.0
E NaN
dtype: float32

EXAMPLE 13
INPUT
import pandas as pd
import numpy as np
S10=pd.Series([39,31,32,34,35],index=['A','B','C','D','E'],
dtype=np.float32)
print("Amount collected by Section A and B (in Rs.)")
print(S10.head(2)*100)
OUTPUT
Amount collected by Section A and B (in Rs.)
A 3900.0
B 3100.0
dtype: float64
EXAMPLE 19.
import pandas as pd
info = pd.Series(data=[31,41,51])
print(info)
print(info>40)
print(info[info>40])
OUTPUT
0 31
1 41
2 51
dtype: int64
0 False
1 True
2 True
dtype: bool
1 41
2 51
dtype: int64
EXAMPLE 20
INPUT
import pandas as pd
idx=[ 'A','B','C','D']
contr=[6700,5600,5000,5200]
s11=pd.Series(contr, idx)
print(s11[s11>5500])
OUTPUT
A 6700
B 5600
dtype: int64

PRACTICAL QUESTIONS

33.

INPUT
import pandas as pd
Ser1 = pd.Series( [34567, 890, 450, 67892, 34677, 78902, 256711,
678291, 637632, 25723, 2367, 11789, 345, 256517])
print("Top 3 biggest areas are :")
print (Ser1.sort_values().tail(3))
print("3 smallest areas are :")
print(Ser1.sort_values().head (3))

#An alternative code for above problem would be:

import pandas as pd
Ser1 = pd.Series( [34567, 890, 450, 67892, 34677, 78902, 256711,
678291, 637632, 25723, 2367, 11789, 345, 256517])
print("Top 3 biggest areas are :")
print (Ser1.sort_values (ascending = False).head (3))
print("3 smallest areas are :")
print (Ser1.sort_values (ascending = False). tail(3))

OUTPUT
Top 3 biggest areas are :
6    256711
8    637632
7    678291
dtype: int64
3 smallest areas are :
12    345
2     450
1     890
dtype: int64
40.
INPUT
import pandas as pd
s5 = pd. Series (data = [200, 100, 500, 300, 400], index= ['I',
'K', 'J', 'L', 'M'])
print("Series object s5:")
print (s5)
print("Cubes of s5 values:")
print (s5 ** 3)

OUTPUT
Series object s5:
I    200
K    100
J    500
L    300
M    400
dtype: int64
Cubes of s5 values:
I      8000000
K      1000000
J    125000000
L     27000000
M     64000000
dtype: int64
41.
INPUT
import pandas as pd
s5 = pd. Series (data = [200, 100, 500, 300, 400], index= ['I',
'K', 'J', 'L', 'M'])
print("Series object s5 :")
print (s5)
s6 = s5 * 2
print("Values in s6 > 15 :")
print (s6[ s6>15])

OUTPUT
Series object s5 :
I    200
K    100
J    500
L    300
M    400
dtype: int64
Values in s6 > 15 :
I     400
K     200
J    1000
L     600
M     800
dtype: int64
LONG ANSWERS
6. import pandas as pd
indx=["item1", "item2", "item3", "item4", "item5"]

s1 = pd.Series( [ 160, 75, 89, 75, 85 ] , index=indx )


s2 = pd.Series( [ 86, 89, 70, 85, 90 ] , index=indx )
s3 = pd.Series( [ 85, 75, 60, 75, 72 ] , index=indx )
s4 = pd.Series( [ 372, 92, 85, 107, 85 ] , index=indx )
s5 = pd.Series( [ 60, 75, 90, 75, 77 ] , index=indx )
s6 = pd.Series( [ 60, 85, 45, 60, 85 ], index=indx )
s7 = pd.Series( [ 286, 75, 66, 75, 86 ], index=indx )
s8 = pd.Series( [ 60, 72, 200, 70, 75 ], index=indx )
s9 = pd.Series( [ 86, 75, 60, 85, 70 ], index=indx )
s10 = pd.Series( [ 60, 89, 90, 75, 85 ] , index=indx )
s11 = pd.Series( [ 70, 75, 78, 86, 55 ] , index=indx )
s12 = pd.Series( [ 86, 85, 85, 75, 53 ] , index=indx )
yearlySal = s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10 + s11
+ s12
print( 'Yearly Sales item-' ,yearlySal )
print('Maximum sales of item made' , end='> ' )
itemlist = list ( yearlySal )

print( indx [ itemlist.index ( max ( itemlist ) ) ] )


print()

List = [ s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 , s10 , s11 , s12 ]


#list of all series
lst=[]

print( "Maximum sales for individual items" )


print()

dic={ 1:s1 , 2:s2 , 3:s3 , 4:s4 , 5:s5 , 6:s6 , 7:s7 , 8:s8 , 9:s9 ,
10:s10 , 11:s11 , 12:s12 }
max = 0
for i in range( 5 ) :
print ( f'Maximum sales of {indx[i]} made: ' , end=' ' )
max = 0
for j in dic:
if max < list ( dic [ j ] ) [ i ] :
max = list( dic[ j ])[ i ]
s=j
print(s)
OUTPUT
Yearly Sales item- item1 1471
item2 962
item3 1018
item4 943
item5 918
dtype: int64
Maximum sales of item made> item1

Maximum sales for individual items

Maximum sales of item1 made: Maximum sales of item1


made: 4
Maximum sales of item2 made: Maximum sales of item2
made: 4
Maximum sales of item3 made: Maximum sales of item3
made: 8
Maximum sales of item4 made: Maximum sales of item4
made: 4
Maximum sales of item5 made: Maximum sales of item5
made: 2
7.
import pandas as pd

Term1 = pd.Series([40,35,25,20,22,26,28,29,23,28])
Term2 = pd.Series([28,15,37,38,45,41,48,47,30,20])
Term3 = pd.Series([36,23,34,31,21,22,23,24,26,28])
final_mark = (Term1*25)/100 + (Term2*25)/100 + (Term3*50)/100

print(final_mark)

OUTPUT
0 35.00
1 24.00
2 32.50
3 30.00
4 27.25
5 27.75
6 30.50
7 31.00
8 26.25
9 26.00
dtype: float64

12.
import pandas as pd
import numpy as np

tab = np.arange(5,55,5)
ser = pd.Series(tab)
print(ser)

OUTPUT
0 5
1 10
2 15
3 20
4 25
5 30
6 35
7 40
8 45
9 50
dtype: int32

DATAFRAME
33.
IMPORT
import pandas as pd
data = [[56000,58000],[70000,68000],[75000,78000]]
ri = ['ZoneA','ZoneB','ZoneC']
cl =['Target','Sales']
df= pd.DataFrame(data,index = ri,columns=cl)
print(df)
df["Orders"]= [6000,6200,6700]
print(df)
OUTPUT
Target Sales
ZoneA 56000 58000
ZoneB 70000 68000
ZoneC 75000 78000
Target Sales Orders
ZoneA 56000 58000 6000
ZoneB 70000 68000 6200
ZoneC 75000 78000 6700
Example 42
import pandas as pd
#Series object df created or loaded
print("No. of rows: ", df.shape[0])
print("No. Of columns : ", df.shape[1])

Example 43
INPUT
import pandas as pd
# Series object df created or loaded
rows = len(df.axes[0])
cols = len(df.axes[1])
print("No. of rows:", rows)
print("No. of columns: ", cols)

Example 44
INPUT
import pandas as pd
: # Series object df created or loaded
print (df.iloc[ [0,2], [2]])
OUTPUT
Weight
0 42
2 66
Example 14
INPUT
import pandas as pd
import numpy as np
d = {"name":['name1','name2','name30,','name4','name5'],"\
zone":['zone1','zone2','zone3','zone4','zone5'],"sales":
[100,200,150,350,250]}

df = pd.DataFrame(d)
print(df)
Example 15.
INPUT
import pandas as pd
import numpy as np
d = {"name":'name',"empno":1}
d1 = {"name":'name1',"empno":2}
d2 = {"name":'name2',"empno":3}
d3 = {"name":'name3',"empno":4}
s = pd.DataFrame([d,d1,d2,d3])
print(s)
OUTPUT
 name empno

0 name 1

1 name1 2

2 name2 3

3 name3 4

>>>

Example 16.
INPUT
import pandas as pd
import numpy as np

list = [{"old price":[10,20,30,50,40]},{"new price":


[15,20,25,36,50]},{"change":[5,0,-5,-14,10]}]
df = pd.DataFrame(list[0])
df["new price"] = list[1]['new price']
df["change"] = list[2]["change"]
print(df)
OUTPUT
old price new price change

0 10 15 5

1 20 20 0

2 30 25 -5

3 50 36 -14

4 40 50 10
Data Frame
Example 4.
INPUT
import pandas as pd
import numpy as z
dict = { 'name' : [1, 2, 3] }
df = pd.DataFrame(dict)
for i , j in df.iteritems() :
print( j )
Example 5.
import pandas as pd
d1 = {'p1': {'1':700,'2':975,'3':970,'4':900}, \
'p2': {'1':490,'2':460,'3':570,'4':590}}
d2 = {'p1': {'1':1100,'2':1275,'3':1270,'4':1400}, \
'p2': {'1':1400,'2':1260,'3':1500,'4':1190}}
df1 = pd.DataFrame(d1)
df2 = pd.DataFrame(d2)
print("Team 1's performance")
print(df1)
print("Team 2's performance")
print(df2)
print("Points earned by both teams")
print(df1+df2)
OUTPUT
Team 1's performance
p1 p2
1 700 490
2 975 460
3 970 570
4 900 590
Team 2's performance
p1 p2
1 1100 1400
2 1275 1260
3 1270 1500
4 1400 1190
Points earned by both teams
p1 p2
1 1800 1890
2 2250 1720
3 2240 2070
4 2300 1780
Example 19
INPUT
import pandas as pd
import numpy as np
names = pd.Series(['Rohan','Karm','Ayush'])
marks = pd.Series([76,56,99])
Stud = {'Names': names,'Marks':marks}
df1 = pd.DataFrame(Stud,columns = ['Names','Marks'])
df1['grade']=np.NaN
print("Internal Values in dataframe")
print(df1)
for (col,colSeries) in df1.iteritems():
lenght =len(colSeries)
if col =='Marks':
lstMrks = []
for row in range(lenght) :
mrks = colSeries[row]
if mrks>=90:
lstMrks.append('A+')
elif mrks>=70:
lstMrks.append('A')
elif mrks>=60:
lstMrks.append('B')
elif mrks>=50:
lstMrks.append('C')
elif mrks>=40:
lstMrks.append('D')
else:
lstMrks.append('F')
df1['Grade']=lstMrks

print("\nDataframe after calculating grades")


print(df1)

OUTPUT
Internal Values in dataframe
Names Marks grade
0 Rohan 76 NaN
1 Karm 56 NaN
2 Ayush 99 NaN

Dataframe after calculating grades


Names Marks grade Grade
0 Rohan 76 NaN A
1 Karm 56 NaN C
2 Ayush 99 NaN A+

You might also like