Ip Project
Ip Project
GUJARAT
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
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))
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"]
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
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
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
OUTPUT
Internal Values in dataframe
Names Marks grade
0 Rohan 76 NaN
1 Karm 56 NaN
2 Ayush 99 NaN