I.P. Practical File
I.P. Practical File
I.P. Practical File
File
NAME: __________________________
JANMESH SINGH BALI
CLASS: _________________
12
SECTION:_______________
A
Solution:
import pandas as pd
def Ser_1to10():
s = pd.Series(range(1,11))
print(s)
Ser_1to10()
OUTPUT:
6|PAGE
2. Write a program to generate a series using a
dictionary to represent month number and month
names.
Solution:
import pandas as pd
def Ser_dic():
di={1:'January',2:'February',3:'March',4:'April',
5:'May',6:'June',7:'July',8:'August',9:'September',
10:'October',11:'November',12:'December'}
s = pd.Series(di)
print(s)
Ser_dic()
OUTPUT:
7|PAGE
3. Write a program to generate a series of marks of 10
students. Give grace marks up to 5 of those who are
having <33 marks and print the new list of the marks.
Solution:
import pandas as pd
def Ser_stumarks():
std_marks = []
for i in range(1,11):
m = int(input("Enter the marks:"))
std_marks.append(m)
s=pd.Series(index=range(1201,1211),data=std_marks)
s[s<33]=s+5
print("New List is:")
print(s[s>=33])
Ser_stumarks()
OUTPUT:
8|PAGE
4. Write a program to generate a series of these
numbers: 33,55,65,29,19,23. Find the sum of those
values which are ending with 3 or 5.
Solution:
import pandas as pd
list=[33,55,65,29,19,23]
ser=pd.Series(list)
val_sum=0
sum5=sum(ser[ser % 10==5])
sum3=sum(ser[ser % 10==3])
print(sum3+sum5)
OUTPUT:
9|PAGE
5. Write a program to generate a series of 10 numbers
with scalar value 33.
Solution:
import pandas as pd
print(pd.Series(33,range(1,11)))
OUTPUT:
10|PAGE
6. Write a program to generate a series with these
numbers: 21, 51, 71, 31, 12. Exchange all these
values of series by shifting each of them to the next
position and by shifting the last value to the first
index.
Solution:
import pandas as pd
import numpy as np
s=pd.Series([21,51,71,31,12])
print(pd.Series(np.roll(s.values,1),index=s.index))
OUTPUT:
11|PAGE
7. Write a program to generate a series of float numbers
from 21.0 to 30.0 with an increment of 1.5 each.
Solution:
import pandas as pd
import numpy as np
def Ser_1to10():
n=np.arange(21,32,1.5)
s=pd.Series(n)
print(s)
Ser_1to10()
OUTPUT:
12|PAGE
8. Write a program to generate a series of 5 elements of
multiples of 7 starting with 35 with index multiply by
3.
Solution:
import pandas as pd
import numpy as np
def Ser_mul7():
a = 35
n = np.arange(a,a*2,7)
s = pd.Series(index=n*3,data=n)
print(s)
Ser_mul7()
OUTPUT:
13|PAGE
9. Write a program to generate a series of 10 numbers
starting with 41 and with the increment of 3. Now
add 7 all odd values and subtract 3 in even values.
Reprint the updated series.
Solution:
import pandas as pd
s=pd.Series(range(41,71,3))
s[s % 2!=0]=s+7
s[s % 2==0]=s-3
print(s)
OUTPUT:
14|PAGE
10. Write a program to generate s1 with prime numbers
between 1 to 25 and s2 with factorial numbers
between 1 to 25.
Solution:
import pandas as pd
import math
s1=pd.Series(x for x in range(1,25)
if all(x % y!=0 for y in range(2,x)))
s2=pd.Series([math.factorial(n) for n in range(25)])
print(s1)
print(s2)
OUTPUT:
15|PAGE
11. Write a program to generate a series with these
numbers: 21, 51, 71, 31, 12. Exchange all these
values of series by shifting each of them one to one
position before and by shifting the first value to last
position.
Solution:
import pandas as pd
import numpy as np
s=pd.Series([21,51,71,31,12])
print(pd.Series(np.roll(s.values,-1),index=s.index))
OUTPUT:
16|PAGE
12. Write a program to generate a series with indexes
starting with 1. Reindex the series with odd values
starting with 4.
Solution:
import pandas as pd
ser_length=int(input(“Enter the length of the
series:”))
data=[]
for i in range(ser_length):
val=int(input(“Enter a val:”))
data.append(val)
ser=pd.Series(data,range(1,ser_length+1))
print(ser)
OUTPUT:
17|PAGE
13. Write a program to generate a series and print the
bottom 3 elements using the tail function.
Solution:
import pandas as pd
ser_length=int(input(“Enter the length of the
series:”))
data=[]
for i in range(ser_length):
val=int(input(“Enter a val:”))
data.append(val)
ser=pd.Series(data)
print(ser.tail(3))
OUTPUT:
18|PAGE
14. Write a program to generate a series and print the top
3 elements using the head function.
Solution:
import pandas as pd
ser_length=int(input(“Enter the length of the series:”))
data=[]
for i in range(ser_length):
val=int(input(“Enter a val:”))
data.append(val)
ser=pd.Series(data)
print(ser.head(3))
OUTPUT:
19|PAGE
15. Write a program to generate a series of 10 numbers.
Change the value of all the elements those values are
multiples of 4.
Solution:
import pandas as pd
numbers=[]
for i in range(1,11):
val=int(input(“Enter a number:”))
numbers.append(val)
ser=pd.Series(numbers)
ser[ser % 4==0]=21
print(ser)
OUTPUT:
20|PAGE
16. Plot following data on line chart:
Solution:
import matplotlib.pyplot as pp
day=[‘Monday’,‘Tuesday’,‘Wednesday’,‘Thursday’,‘Friday’]
inc=[510,350,475,580,600]
pp.plot(day,inc,label=‘Income’,color=‘r’,linestyle=‘dashed’,
marker=‘D’)
pp.title(“The Weekly Income Report”)
pp.xlabel(“Days”)
pp.ylabel(“Income”)
pp.legend()
pp.show()
21|PAGE
OUTPUT:
22|PAGE
17. Observe the given data for monthly views of one of
the youtube channels for 6 months. Plot them on the
line chart.
Month January February March April May June
Solution:
import matplotlib.pyplot as pp
mon=[‘January’,’February’,’March’,’April’,’May’,’June’]
views=[2500,2100,1700,3500,3000,3800]
pp.plot(mon,views,label=‘Views State’,color=‘r’,
linestyle=‘dashed’,linewidth=4,marker=‘o’,
markerfacecolor=‘k’,markeredgecolor=‘b’)
23|PAGE
pp.title(“Youtube Stats”)
pp.xlabel(“Months”)
pp.ylabel(“Views”)
pp.legend()
pp.show()
OUTPUT:
24|PAGE
18. Consider the following data of a medical store and
subplot sanitizer data and handwash data.
Months Mask Sanitizer Handwash
March 1500 4400 6500
April 3500 4500 5000
May 6500 5500 5800
June 6700 6000 6300
July 6000 5600 6200
August 6800 6300 4500
Solution:
import matplotlib.pyplot as pp
mon=[‘March’,’April’,’May’,’June’,’July’,’August’]
san=[4400,4500,5500,6000,5600,6300]
hw=[6500,5000,5800,6300,6200,4500]
pp.subplot(2,1,1)
pp.plot(mon,san,label=‘Sanitizer’,color=‘b’,linestyle=‘dashed’
,linewidth=4,marker=‘o’,markerfacecolor=‘k’,
markeredgecolor=‘r’)
pp.title(“Fitwell Medical Store”)
pp.legend()
pp.subplot(2,1,2)
pp.plot(mon,hw,label=‘Handwash’,color=‘r’,linestyle=‘dashed’
,linewidth=4,marker=‘v’,markerfacecolor=‘k’,
markeredgecolor=‘b’)
pp.xlabel(“Months”)
pp.ylabel(“Covid Protections”)
pp.legend()
pp.show()
25|PAGE
OUTPUT:
26|PAGE
19. Display following bowling figures through bar
chart:
Overs Runs
1 6
2 8
3 10
4 15
Solution:
import matplotlib.pyplot as pp
overs=[1,2,3,4]
runs=[6,8,10,15]
p.bar(overs,runs,color=‘m’)
. pp.xlabel(‘Overs’)
pp.ylabel(‘Runs’)
pp.title(‘Bowling Spell Analysis’)
pp.show()
OUTPUT:
27|PAGE
20. Write a program to plot a range from 1 to 30 with
step value 4. Use following algebraic expression to
show data.
y = 5*x+2
Solution:
import matplotlib.pyplot as pp
import numpy as np
x=np.arange(1,30,4)
y=5*x+2
pp.plot(x,y)
pp.show()
OUTPUT:
28|PAGE
SQL COMMANDS…
Solution:
29|PAGE
4. Display details of all the loans.
Solution:
Solution:
30|PAGE
6. Display details of all the loans with less than 40
installments.
Solution:
Solution:
31|PAGE
8. Display the int_rate of all the loans started after
01-04-2009.
Solution:
Solution:
32|PAGE
10. Display the amount of various loans from the table
loan_accounts. A loan amount should appear only
once.
Solution:
Solution:
33|PAGE
12. Display the cust_name and loan_amount for all
the loans for which the loan amount is less than
500000 or int_rate is more than 12.
Solution:
Solution:
34|PAGE
14. Display the cust_name and loan_amount for all the
loans for which the number of installments are 24,
36, or 48.
Solution:
Solution:
35|PAGE
16. Display the accno, cust_name, loan_amount for all
the loans for which the cust_name ends with
“Sharma”.
Solution:
Solution:
36|PAGE
18. Display the details of all the loans in the ascending
order of their loan_amount.
Solution:
37|PAGE
20. Put the interest rate 11.50% for all the loans for
which interest rate is null.
Solution:
Solution:
Solution:
38|PAGE
23. Add another category of type char(1) in the
loan_accounts table.
Solution:
39|PAGE
c. Select dayname(start_date) from loan_accounts;
Solution:
Solution:
Solution:
40|PAGE
b. Select round(543.5694,2) , round(543.5694),
round(543.5634,-1);
Solution:
Solution:
Solution:
41|PAGE
e. Select year(curdate()), month(curdate()), day(curdate());
Solution:
Solution:
g. Select mid(“informatics”,3,4),substr(“practices”,3);
Solution:
42|PAGE