Ipclass 12
Ipclass 12
import pandas as pd
import numpy as np
dictionary={'A':10,'B':20,'C':30}
series=pd.Series(dictionary)
print(series)
print()
s=pd.Series(np.array([1,3,4,7,8,8,9]))
print(s)
#PROGRAM 1
#OUTPUT
A 10
B 20
C 30
dtype: int64
0 1
1 3
2 4
3 7
4 8
5 8
6 9
dtype: int32
#PROGRAM 2
import pandas as pd
import numpy as np
list=[33,55,65,29,19,23]
s=pd.Series(list)
sum5=sum(s[s%10==5])
sum3=sum(s[s%10==3])
print(sum3+sum5)
#PROGRAM 2
#OUTPUT
176
#PROGRAM 3
import pandas as pd
s=pd.Series(range(41,71,3))
print("Original list:")
print(s)
for i in range(0,s.size):
if s[i]%2==0:
s[i]=s[i]-3
elif s[i]%2!=0:
s[i]=s[i]+7
print("updated list")
print(s)
#PROGRAM 3
#OUTPUT
runfile('C:/ip practical programs/p3.py', wdir='C:/ip practical programs')
Original list:
0 41
1 44
2 47
3 50
4 53
5 56
6 59
7 62
8 65
9 68
dtype: int64
updated list
0 48
1 41
2 54
3 47
4 60
5 53
6 66
7 59
8 72
9 65
dtype: int64
#PROGRAM 4
#OUTPUT
runfile('C:/ip practical programs/p4.py', wdir='C:/ip practical programs')
class pass-percentage
0 I 100.0
1 II 100.0
2 III 100.0
3 IV 100.0
4 V 100.0
5 VI 100.0
6 VII 100.0
7 VIII 100.0
8 IX 100.0
9 X 98.6
10 XI 100.0
11 XII 99.0
class object
pass-percentage float64
dtype: object
(12, 2)
#PROGRAM 5
import pandas as pd
l=[1,2,3,4,5,6,7,8,9]
print("Enter for slicing without step value")
print("Enter for slicing with step value")
while True:
ch= int(input("Enter your choice:"))
if ch==1:
s=pd.Series(l)
print(s)
print("Slicing without step value")
a=int(input("Enter the start value:"))
b=int(input("Enter the end value:"))
print(s[a:b])
elif ch==2:
s=pd.Series(l)
print("Slicing with step value")
a=int(input("Enter the start value:"))
b=int(input("Enter the end value:"))
c=int(input("Enter the step value:"))
print(s[a:b:c])
else:
print("INVALID")
ans=input("Do you want to continue:")
if ans!="yes":
break
#PROGRAM 5
#OUTPUT
runfile('C:/ip practical programs/program5.py', wdir='C:/ip practical programs')
0 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
dtype: int64
2 3
3 4
4 5
5 6
dtype: int64
3 4
5 6
7 8
dtype: int64
import pandas as pd
marks=pd.Series(data=[20,45,67,45,78,87,35,56])
print("Enter the option for displaying all the marks who scored above 75")
print("Enter the option for displaying the marks who scored below 75")
print("Enter the option for displaying the marks in ascending order")
print("Enter the option for displaying the marks in descending order")
while True:
ch=int(input("Enter your choice:"))
if ch==1:
print("The marks who scored above 75")
print(marks[marks>75])
if ch==2:
print("The marks who scored below 75")
print(marks[marks<75])
if ch==3:
print("The marks in ascending order")
print(marks.sort_values())
if ch==4:
print("The marks in descending order")
print(marks.sort_values(ascending=False))
else:
print("INVALID")
ans=input("Do you want to continue:")
if ans!="yes":
break
#PROGRAM 6
#OUTPUT
runfile('C:/ip practical programs/program6.py', wdir='C:/ip practical programs')
Enter the option for displaying all the marks who scored above 75
Enter the option for displaying the marks who scored below 75
4 78
5 87
dtype: int64
INVALID
0 20
1 45
2 67
3 45
6 35
7 56
dtype: int64
INVALID
0 20
6 35
1 45
3 45
7 56
2 67
4 78
5 87
dtype: int64
INVALID
5 87
4 78
2 67
7 56
1 45
3 45
6 35
0 20
dtype: int64
import pandas as pd
states=pd.DataFrame({'POPULATION':
[120251,153242,152364,136548,102020],'HOSPITALS':
[1520,1200,1100,1212,1420],'SCHOOLS':
[1100,1200,1300,1100,1420],'DISTRICTS':
[20,30,14,20,15]},index=["TN","MP","KERALA","AP","DEL"])
print(states)
for (ri,rv) in states.iterrows():
print("ROW INDEX IS:",ri)
print("ROW VALUES ARE:")
print(rv)
print("**************************")
for (col_name,col_values) in states.items():
print("COLUMN NAME IS:",col_name)
print("COLUMN VALUES ARE:")
print(col_values)
print("**************************")
#PROGRAM 7
#OUTPUT
runfile('C:/ip practical programs/program7.py', wdir='C:/ip practical programs')
POPULATION 120251
HOSPITALS 1520
SCHOOLS 1100
DISTRICTS 20
**************************
POPULATION 153242
HOSPITALS 1200
SCHOOLS 1200
DISTRICTS 30
**************************
POPULATION 152364
HOSPITALS 1100
SCHOOLS 1300
DISTRICTS 14
**************************
POPULATION 136548
HOSPITALS 1212
SCHOOLS 1100
DISTRICTS 20
Name: AP, dtype: int64
**************************
POPULATION 102020
HOSPITALS 1420
SCHOOLS 1420
DISTRICTS 15
**************************
TN 120251
MP 153242
KERALA 152364
AP 136548
DEL 102020
**************************
TN 1520
MP 1200
KERALA 1100
AP 1212
DEL 1420
TN 1100
MP 1200
KERALA 1300
AP 1100
DEL 1420
**************************
TN 20
MP 30
KERALA 14
AP 20
DEL 15
**************************
#PROGRAM 11
Write a menu driven program to create a two Data Frame and perform arithmetic
operations.
Source code:
import pandas as pd
d1={"English":[60,65,67],"Economics":[68,87,57],"Maths":[78,89,99],"IP":[78,86,69]}
d2={"English":[70,65,87],"Economics":[88,97,67],"Maths":[58,89,100],"IP":[68,86,99]}
data1=pd.DataFrame(d1)
print(data1)
data2=pd.DataFrame(d2)
print(data2)
print("enter 1 for addition")
print("enter 2 for subtraction")
print("enter 3 for multiplication")
print("enter 4 for division")
while True:
ch=int(input("enter your choice:"))
if ch==1:
add=data1.add(data2)
print(add)
if ch==2:
sub=data1.sub(data2)
print(sub)
if ch==3:
mul=data1.mul(data2)
print(mul)
if ch==4:
div=data1.div(data2)
print(div)
else:
print("Invalid")
a=input("Do you want to continue:")
if a!="yes":
break
#Output
0 60 68 78 78
1 65 87 89 86
2 67 57 99 69
0 70 88 58 68
1 65 97 89 86
2 87 67 100 99
enter 1 for addition
Invalid
0 -10 -20 20 10
1 0 -10 0 0
Invalid
Invalid