Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Ip Class 12 Practical File

Download as pdf or txt
Download as pdf or txt
You are on page 1of 61

KASHISH SINGH

CLASS :12D
ROLL NO:30

INFORMATION PRACTICES
PRACICAL FILE
PROGRAM1
import pandas as pd
s1= pd.Series()
s1
Series([], dtype: object)

PROGRAM2
import pandas as pd
series1= pd.Series([10,20,30,40])
print(series1)
0 10
1 20
2 30
3 40
dtype: int64

PROGRAM3
import pandas as pd
months= ['jan','feb','mar','apl','may','june']
no_days= [31,28,31,30,31,30]
series= pd.Series(no_days,index=months)
print(series)
jan 31
feb 28
mar 31
apl 30
may 31
june 30
dtype: int64
PROGRAM4
import pandas as pd
series1= pd.Series(range(5))
series1
0 0
1 1
2 2
3 3
4 4

PROGRAM5
import pandas as pd
s=pd.Series(range(1,15,3),index=[x for x in "abcde"])
print(s)
a 1
b 4
c 7
d 10
e 13
dtype: int64

PROGRAM6
import pandas as pd
series1=pd.Series([2,4,6,7.5])
series1
0 2.0
1 4.0
2 6.0
3 7.5
dtype: float64
PROGRAM7
import pandas as pd
import numpy as np
sobj = pd.Series([7.5, 5.4, np.NaN, -34.5])
print(sobj)
0 7.5
1 5.4
2 NaN
3 -34.5
dtype: float64

PROGRAM8
import pandas as pd
series1 = pd.Series(55, index = ['a', 'b', 'c', 'd', 'e'])
print(series1)
a 55
b 55
c 55
d 55
e 55
dtype: int64

import pandas as pd
s1 = pd.Series(10, index =range(0,3))
print(s1)
0 10
1 10
2 10
dtype: int64

PROGRAM9
import pandas as pd
s= pd.Series('welcome to TCS',
index=['sonia','vinay','shaurya','rahul'])
print(s)
sonia welcome to TCS
vinay welcome to TCS
shaurya welcome to TCS
rahul welcome to TCS
dtype: object

PROGRAM10
>>> import pandas as pd
>>> series = pd.Series({"Jan":31, "Feb":28, "Mar":31,
"Apr":30})
>>> print(series)
Jan 31
Feb 28
Mar 31
Apr 30
dtype: int64

PROGRAM11
import pandas as pd
import numpy as np
s1 = np.arange(10,15)
print(s1)
[10 11 12 13 14]
sobj = pd.Series(index =s1, data=s1*4)
sobj
10 40
11 44
12 48
13 52
14 56
dtype: int32

PROGRAM12
import pandas as pd
import numpy as np
s1 = np.arange(10,15)
s1
array([10, 11, 12, 13, 14])
>>> s2 = pd.Series(np.arange(10,16,1), index = ['a', 'b', 'c',
'd', 'e', 'f'])
>>> s2
a 10
b 11
c 12
d 13
e 14
f 15
dtype: int32
>>> sobj = pd.Series(index= s1, data=s1**2)
>>> sobj
10 100
11 121
12 144
13 169
14 196
dtype: int32

PROGRAM13
import pandas as pd
import numpy as np
array1=np.array([10,20,30,40])
series1=pd.Series(array1)
print(series1)
output:
0 10
1 20
2 30
3 40
dtype: int32

PROGRAM14
import pandas as pd
import numpy as np
array1 = np.array([10,20,30,40])
series1= pd.Series(array1)
print(series1)
0 10
1 20
2 30
3 40
dtype: int32

PROGRAM 15
import pandas as pd
series2=pd.Series([10,20,30,40,50],index=['a','b','c','d','e']
)
series2['d']
40
series2[['a','c','e']]
a 10
c 30
e 50
dtype: int64

PROGRAM16
import pandas as pd
s = pd.Series([1,2,3,4,5], index = ['a','b','c','d','e'])
print(s[0])
print(s[:3])
print(s[-3:])
print(s[:])
print(s[1:4])
print(s[::-1])
print(s[0::2])
1
a 1
b 2
c 3
dtype: int64
c 3
d 4
e 5
dtype: int64
a 1
b 2
c 3
d 4
e 5
dtype: int64
b 2
c 3
d 4
dtype: int64
e 5
d 4
c 3
b 2
a 1
dtype: int64
a 1
c 3
e 5
dtype: int64

PROGRAM17
import pandas as pd
s=pd.Series(range(1,15,3),index=[x for x in 'abcde'])
s.index
Index(['a', 'b', 'c', 'd', 'e'], dtype='object')
s.values
array([ 1, 4, 7, 10, 13], dtype=int64)

PROGRAM18
import pandas as pd
series1=pd.Series([10,20,30,40,50],index=['a','b','c','d','e']
)
print(series1)
print(series1.head(2))
print(series1.head())
print(series1.tail(2))
print(series1.tail())
print(series1.head(-2))
print(series1.tail(-2))
a 10
b 20
c 30
d 40
e 50
dtype: int64
a 10
b 20
dtype: int64
a 10
b 20
c 30
d 40
e 50
dtype: int64
d 40
e 50

PROGRAM20
import pandas as pd
Name = ['Shruti', 'Renu', 'Rinku', 'Nidhi', 'Tinku',
'Vidooshi', 'Rohit']
Marks = [80,60,89,90,78,82,99]
stud = pd.Series(Marks, index=Name)
print(stud)
shruti 80
renu 60
rinku 89
nidhi 90
tinku 78
vidoosi 82
rohit 99
dtype: int64

PROGRAM21
import pandas as pd
a = pd.Series([1,2,7,5,4])
b = pd.Series([4,8,9,5,10])
print("First series is: ")
print(a)
print("Second series is: ")
print(b)
print("Comparing the elements of both the series ")
print("EPractical Implementationuals")
print(a == b)
print("Greater than: ")
print(a > b)
print("Less than: ")
print(a < b)
First series is:
0 1
1 2
2 7
3 5
4 4
dtype: int64
Second series is:
0 4
1 8
2 9
3 5
4 10
dtype: int64
0 False
1 False
2 False
3 True
4 False
dtype: bool
Greater than:
0 False
1 False
2 False
3 False
4 False
dtype: bool
Less than:
0 True
1 True
2 True
3 False
4 True
dtype: bool

PROGRAM22
import pandas as pd
student_marks = pd.Series({'Vijaya':80, 'Rahul':92,
'Meghna':67, 'Radhiks':95, 'Shaurya':97})
student_age = pd.Series({'Vijaya':32, 'Rahul':28, 'Meghna':30,
'Radhiks':25, 'Shaurya':20})
student_df = pd.DataFrame({'Marks':student_marks,
'Age':student_age})
print(student_df)
Marks Age
Vijaya 80 32
Rahul 92 28
Meghna 67 30
Radhiks 95 25
Shaurya 97 20

PROGRAM23
import pandas as pd
Stud_Result = {"Name":pd.Series(['Rinku', 'Deep', 'Shaurya',
'Radhika']),
"English":pd.Series([89,78,89,90]),
"Economic":pd.Series([87,80,60,84]),
"Informatics Practices":pd.Series([89,78,67,90])}
df = pd.DataFrame(Stud_Result)
print(df)
Name English Economic Informatics Practices
0 Rinku 89 87 89
1 Deep 78 80 78
2 Shaurya 89 60 67
3 Radhika 90 84 90

PROGRAM24
import pandas as pd
newstudent = [{'Rinku':67, "Ritu":78, "Ajay":75, "Pankaj":88,
"Aditya":92},
{'Rinku':77, "Ritu":58, "Ajay":87, "Pankaj":65},
{'Rinku':88, "Ajay":67, "Pankaj":74, "Aditya":70}]
newdf = pd.DataFrame(newstudent)
print(newdf)
Rinku Ritu Ajay Pankaj Aditya
0 67 78.0 75 88 92.0
1 77 58.0 87 65 NaN
2 88 NaN 67 74 70.0

PROGRAM25
import pandas as pd
import numpy as np
array = np.array([[67,78,75,78],[67,78,75,88],
[78,67,89,90],[78,88,98,90]])
column_values = ['English','Economics','IP','Accounts']
df = pd.DataFrame(data = array, columns = column_values)
print(df)

PROGRAM26
import pandas as pd
student = {'Name':['Rinku', 'Ritu', 'Ajay', 'Pankaj',
'Aditya'], 'English':[67,78,75,88,92],
'Economics':[78,67,89,90,56], 'IP':[78,88,98,90,87],
'Accounts':[77,70,80,67,86]}
df = pd.DataFrame(student, index =
['Sno1','Sno2','Sno3','Sno4','Sno5'])
print(df)
Name English Economics IP Accounts
Sno1 Rinku 67 78 78 77
Sno2 Ritu 78 67 88 70
Sno3 Ajay 75 89 98 80
Sno4 Pankaj 88 90 90 67
Sno5 Aditya 92 56 87 86

PROGRAM27
df.set_index('Name', inplace=True)
print(df)
English Economics IP Accounts
Name
Rinku 67 78 78 77
Ritu 78 67 88 70
Ajay 75 89 98 80
Pankaj 88 90 90 67
Aditya 92 56 87 86

PROGRAM 28
df.reset_index(inplace=True)
print(df)
index Name English Economics IP Accounts
0 0 Rinku 67 78 78 77
1 1 Ritu 78 67 88 70
2 2 Ajay 75 89 98 80
3 3 Pankaj 88 90 90 67
4 4 Aditya 92 56 87 86

PROGRAM29
import pandas as pd
student = {'Name':['Rinku', 'Ritu', 'Ajay', 'Pankaj',
'Aditya'], 'English':[67,78,75,88,92],
'Economics':[78,67,89,90,56], 'IP':[78,88,98,90,87],
'Accounts':[77,70,80,67,86]}
print("Series generated as:")
print(student)
df = pd.DataFrame(student)
print("DataFrame for student")
print(df)
Series generated as:
{'Name': ['Rinku', 'Ritu', 'Ajay', 'Pankaj', 'Aditya'],
'English': [67, 78, 75, 88, 92], 'Economics': [78, 67, 89,
90, 56], 'IP': [78, 88, 98, 90, 87], 'Accounts': [77, 70, 80,
67, 86]}
DataFrame for student
Name English Economics IP Accounts
0 Rinku 67 78 78 77
1 Ritu 78 67 88 70
2 Ajay 75 89 98 80
3 Pankaj 88 90 90 67
4 Aditya 92 56 87 86

PROGRAM30
import pandas as pd
al = [101,102,103,104,105]
df = pd.DataFrame(al)
df.columns = ['Admno']
print(df)
Admno
0 101
1 102
2 103
3 104
4 105

PROGRAM31
import pandas as pd
s = [['Rinku',79,72], ['Ritu',75,73], ['Ajay',80,76]]
print("Series generatd as:")
print(s)
df = pd.DataFrame(s, columns = ['Name','IP','BST'])
print(df)
df.rename(columns={'Name':'Nm','IP':'Informatics Practices'},
inplace= True)
print(df)
Series generatd as:
[['Rinku', 79, 72], ['Ritu', 75, 73], ['Ajay', 80, 76]]
Name IP BST
0 Rinku 79 72
1 Ritu 75 73
2 Ajay 80 76
Nm Informatics Practices BST
0 Rinku 79 72
1 Ritu 75 73
2 Ajay 80 76

PROGRAM32
import pandas as pd
al = [101,102,103,104,105]
df = pd.DataFrame(al)
df['Name']=['Shruti','Gunjan','Tanya','Kriti','Vineet']
print(df)
df['Physics']=pd.Series([89,78,65,45,55])
df['Chemistry']=pd.Series([77,89,74,60,56])
df['Maths']=pd.Series([88,65,79,78,58])
df['Total']= df['Physics']+df['Chemistry']+df['Maths']
print(df)
0 Name
0 101 Shruti
1 102 Gunjan
2 103 Tanya
3 104 Kriti
4 105 Vineet
0 Name Physics Chemistry Maths Total
0 101 Shruti 89 77 88 254
1 102 Gunjan 78 89 65 232
2 103 Tanya 65 74 79 218
3 104 Kriti 45 60 78 183
4 105 Vineet 55 56 58 169

PROGRAM33
import pandas as pd
test = {"Name":['Ritu','Ajay','Manu','Rohit','Reema'],
"Score":[67,78,89,56,90],
"No_attempts":[4,2,1,1,3]}
test_result = pd.DataFrame(test, index =
['Respondant0','Respondant1','Respondant2','Respondant3','Resp
ondant4'])
print(test_result)
test_result['Practical
Implementationualify']=['NO','YES','NO','YES','YES']
print("dataframe after adding new column")
print(test_result)
Name Score No_attempts
Respondant0 Ritu 67 4
Respondant1 Ajay 78 2
Respondant2 Manu 89 1
Respondant3 Rohit 56 1
Respondant4 Reema 90 3
dataframe after adding new column
Name Score No_attempts Practical Implementationualify
Respondant0 Ritu 67 4 NO
Respondant1 Ajay 78 2 YES
Respondant2 Manu 89 1 NO
Respondant3 Rohit 56 1 YES
Respondant4 Reema 90 3 YES

PROGRAM34
import pandas as pd
student = {"Roll No":[1,2,3,4,5],
"Name":['Rinku','Deep','Shaurya','Radhika','Rohit'],
"English":[89,78,89,90,79],
"Economics":[87,80,60,84,77],
"IP":[89,78,67,90,92]}
df = pd.DataFrame(student)
print(df)
print(df.iloc[0:3])
print(df.iloc[0:3,0:3])
print(df.iloc[1:3])
Roll No Name English Economics IP
0 1 Rinku 89 87 89
1 2 Deep 78 80 78
2 3 Shaurya 89 60 67
3 4 Radhika 90 84 90
4 5 Rohit 79 77 92
Roll No Name English Economics IP
0 1 Rinku 89 87 89
1 2 Deep 78 80 78
2 3 Shaurya 89 60 67
Roll No Name English
0 1 Rinku 89
1 2 Deep 78
2 3 Shaurya 89
Roll No Name English Economics IP
1 2 Deep 78 80 78
2 3 Shaurya 89 60 67

PROGRAM35
import pandas as pd
student_marks = pd.Series({'Vijaya':60, 'Rahul':92,
'Megna':67, 'Radhika':95, 'Shaurya':97})
student_age = pd.Series({'Vijaya':32, 'Rahul':28, 'Megna':30,
'Radhika':25, 'Shaurya':20})
student_df = pd.Series({'Marks':student_marks,
'Age':student_age})
print(student_df)
print(student_df.sort_values(by=['Marks']))
Marks Vijaya 60
Rahul 92
Megna 67
Radh...
Age Vijaya 32
Rahul 28
Megna 30
Radh...
dtype: object

PROGRAM37
import pandas as pd
student = {'Unit Test-1':[5,6,8,3,10], 'Unit Test-
2':[7,8,9,6,15]}
student1 = {'Unit Test-1':[3,3,6,6,8], 'Unit Test-
2':[5,9,8,10,5]}
ds = pd.DataFrame(student)
ds1 = pd.DataFrame(student1)
print(ds)
print(ds1)
print("Subraction")
print(ds.sub(ds1))
print("rsub")
print(ds.rsub(ds1))
print("Addition")
print(ds.add(ds1))
print("radd")
print(ds.radd(ds1))
print("Multiplication")
print(ds.mul(ds1))
print("Division")
print(ds.div(ds1))

OUTPUT:
Unit Test-1 Unit Test-2
0 5 7
1 6 8
2 8 9
3 3 6
4 10 15
Unit Test-1 Unit Test-2
0 3 5
1 3 9
2 6 8
3 6 10
4 8 5
Subraction
Unit Test-1 Unit Test-2
0 2 2
1 3 -1
2 2 1
3 -3 -4
4 2 10
rsub
Unit Test-1 Unit Test-2
0 -2 -2
1 -3 1
2 -2 -1
3 3 4
4 -2 -10
Addition
Unit Test-1 Unit Test-2
0 8 12
1 9 17
2 14 17
3 9 16
4 18 20
radd
Unit Test-1 Unit Test-2
0 8 12
1 9 17
2 14 17
3 9 16
4 18 20
Multiplication
Unit Test-1 Unit Test-2
0 15 35
1 18 72
2 48 72
3 18 60
4 80 75
Division
Unit Test-1 Unit Test-2
0 1.666667 1.400000
1 2.000000 0.888889
2 1.333333 1.125000
3 0.500000 0.600000
4 1.250000 3.000000

PROGRAM38
import pandas as pd
a = [2,5,6,7,8]
b = [5,8,8,4,10]
df1 = pd.DataFrame(a)
df2 = pd.DataFrame(b)
0
0 2
1 5
2 6
3 7
4 8
0
0 5
1 8
2 8
3 4
4 10

PROGRAM40

import pandas as pd
Emp_data={'Empid':['rohit','Pooja','Princi','Shaurya','Sonia',
'Vinay'],
'Doj':['12-01-2012','15-01-2012','05-09-2007','17-
01-2012','05-09-2007','16-01-2012']}
df=pd.DataFrame(Emp_data)
print(df)
print(df.head())
print(df.tail())

OUTPUT:

Empid Doj
0 rohit 12-01-2012
1 Pooja 15-01-2012
2 Princi 05-09-2007
3 Shaurya 17-01-2012
4 Sonia 05-09-2007
5 Vinay 16-01-2012
Empid Doj
0 rohit 12-01-2012
1 Pooja 15-01-2012
2 Princi 05-09-2007
3 Shaurya 17-01-2012
4 Sonia 05-09-2007
Empid Doj
1 Pooja 15-01-2012
2 Princi 05-09-2007
3 Shaurya 17-01-2012
4 Sonia 05-09-2007
5 Vinay 16-01-2012
import pandas as pd
Emp_data={'Empid':[101,102,103,104,105,106],

'Empid':['rohit','Pooja','Princi','Shaurya','Sonia','Vinay'],
'Doj':['12-01-2012','15-01-2012','05-09-2007','17-
01-2012','05-09-2007','16-01-2012']}
df=pd.DataFrame(Emp_data)
print(df)
print(df.head(2))
print(df.tail(2))
print(df[2:5])
OUTPUT
============== RESTART: C:/Users/Dev/Documents/dev python/2.py
==============
Empid Doj
0 rohit 12-01-2012
1 Pooja 15-01-2012
2 Princi 05-09-2007
3 Shaurya 17-01-2012
4 Sonia 05-09-2007
5 Vinay 16-01-2012
Empid Doj
0 rohit 12-01-2012
1 Pooja 15-01-2012
Empid Doj
4 Sonia 05-09-2007
5 Vinay 16-01-2012
Empid Doj
2 Princi 05-09-2007
3 Shaurya 17-01-2012
4 Sonia 05-09-2007
PROGRAM41
import pandas as pd
d1={'roll_no':[10,11,12,13,14,15],
'name':['ankit','pihu','rinku','yash','vijay','nikhil']}
df1=pd.DataFrame(d1,columns=['roll_no','name'])
print(df1)
d2={'roll_no':[1,2,3,4,5,6],
'name':['Renu''Jatin''Deep''Guddu''Chhaya','Sahil']}
df2 =pd.DataFrame(d2,columns = ['roll_no','name'])
print(df2)
OUTPUT
roll_no name
0 10 ankit
1 11 pihu
2 12 rinku
3 13 yash
4 14 vijay
5 15 nikhil

PROGRAM42
import pandas as pd
d1={'roll_no':[10,11,12,13,14,15],
'name':['ankit','pihu','rinku','yash','vijay','nikhil']}
d2={'roll_no':[20,21,22,23,24,25],

'name':['Shaurya','Pinky','Anubhav','Khushi','Vinay','Neetu']}
df1=pd.DataFrame(d1)
df2=pd.DataFrame(d2)
df3=pd.concat([df1,df2])
print(df3)
OUTPUT
roll_no name
0 10 ankit
1 11 pihu
2 12 rinku
3 13 yash
4 14 vijay
5 15 nikhil
0 20 Shaurya
1 21 Pinky
2 22 Anubhav
3 23 Khushi
4 24 Vinay
5 25 Neetu

PROGRAM43
import pandas as pd
d1={'roll_no':[10,11,12,13,14,15],
'name':['ankit','pihu','rinku','yash','vijay','nikhil']}
d2={'roll_no':[20,21,22,23,24,25],

'name':['Shaurya','Pinky','Anubhav','Khushi','Vinay','Neetu']}
df1=pd.DataFrame(d1)
df2=pd.DataFrame(d2)
df3=pd.concat([df1,df2],ignore_index=True)
print(df3)
OUTPUT
roll_no name
0 10 ankit
1 11 pihu
2 12 rinku
3 13 yash
4 14 vijay
5 15 nikhil
6 20 Shaurya
7 21 Pinky
8 22 Anubhav
9 23 Khushi
10 24 Vinay
11 25 Neetu

PROGRAM44
import pandas as pd
d1={'roll_no':[10,11,12,13,14,15],
'name':['ankit','pihu','rinku','yash','vijay','nikhil']}
d2={'roll_no':[20,21,22,23,24,25],

'name':['Shaurya','Pinky','Anubhav','Khushi','Vinay','Neetu']}
df1=pd.DataFrame(d1)
df2=pd.DataFrame(d2)
df3=pd.concat([df1,df2],axis=1)
print(df3)
OUTPUT
roll_no name roll_no name
0 10 ankit 20 Shaurya
1 11 pihu 21 Pinky
2 12 rinku 22 Anubhav
3 13 yash 23 Khushi
4 14 vijay 24 Vinay
5 15 nikhil 25 Neetu

PROGRAM45
import pandas as pd
d1={'roll_no':[10,11,12,13,14,15],
'name':['ankit','pihu','rinku','yash','vijay','nikhil']}
d2={'roll_no':[20,21,22,23,24,25],

'name':['Shaurya','Pinky','Anubhav','Khushi','Vinay','Neetu']}
d3={'roll_no':[10,21,12,13,24,15],

'name':['jeet','Ashima','Shivin','Kiran','Tanmay','Rajat']}
df1=pd.DataFrame(d1)
df2=pd.DataFrame(d2)
df3=pd.concat([df1,df2])
df4=pd.DataFrame(d3)
df5=pd.merge(df3,df4,on='roll_no')
print(df5)

OUTPUT
roll_no name_x name_y
0 10 ankit jeet
1 12 rinku Shivin
2 13 yash Kiran
3 15 nikhil Rajat
4 21 Pinky Ashima
5 24 Vinay Tanmay

PROGRAM46

import pandas as pd
d1={'roll_no':[10,11,12,13,14,15],
'name':['ankit','pihu','rinku','yash','vijay','nikhil']}
d2={'roll_no':[20,21,22,23,24,25],
'name':['Shaurya','Pinky','Anubhav','Khushi','Vinay','Neetu']}
d3={'roll_no':[10,21,12,13,24,15],

'name':['jeet','Ashima','Shivin','Kiran','Tanmay','Rajat']}
df1=pd.DataFrame(d1)
df2=pd.DataFrame(d2)
df3=pd.concat([df1,df2])
df4=pd.DataFrame(d3)
df5=pd.merge(df3,df4,left_on='roll_no',right_on='roll_no')
print(df5)
OUTPUT
roll_no name_x name_y
0 10 ankit jeet
1 12 rinku Shivin
2 13 yash Kiran
3 15 nikhil Rajat
4 21 Pinky Ashima
5 24 Vinay Tanmay
EX47
import pandas as pd
d1={'roll_no':[10,11,12,13,14,15],
'name':['ankit','pihu','rinku','yash','vijay','nikhil']}
d2={'roll_no':[20,21,22,23,24,25],

'name':['Shaurya','Pinky','Anubhav','Khushi','Vinay','Neetu']}
df1=pd.DataFrame(d1)
df2=pd.DataFrame(d2)
df1=df1.append(df2)
print(df1)

PROGRAM47
import pandas as pd
d1={'roll_no':[10,11,12,13,14,15],
'name':['ankit','pihu','rinku','yash','vijay','nikhil']}
d2={'roll_no':[20,21,22,23,24,25],

'name':['Shaurya','Pinky','Anubhav','Khushi','Vinay','Neetu']}
df1=pd.DataFrame(d1)
df2=pd.DataFrame(d2)
df1=df1.append(df2)
print(df1)

PROGRAM51
import pandas as pd
d1={'roll_no':[10,11,12,13,14,15],
'name':['ankit','pihu','rinku','yash','vijay','nikhil']}
d2={'roll_no':[20,21,22,23,24,25],

'name':['Shaurya','Pinky','Anubhav','Khushi','Vinay','Neetu']}
df1=pd.DataFrame(d1)
df2=pd.DataFrame(d2)
df1=df1.append(df2)
print(df1)

PROGRAM52
import pandas as pd
df= pd.read_csv('I:\\Data\\Employee.csv',nrows = 5)
print(df)

output:
Empid Name Age
City Salary
0 100.0 Ritesh 25.0 Mumbai
15000.0
1 101.0 Aakash 26.0
Goa 16000.0
2 NaN NaN NaN
NaN NaN
3 102.0 Mahima 27.0 Hydrabad
20000.0
4 103.0 Lakshay 23.0
Delhi 18000.0
MATPLOTLIB PROGRAMS

PROGRAM1

import matplotlib.pyplot as plt


plt.plot([1,2,3],[5,7,4])
plt.show()

OUTPUT:

PROGRAM2
import matplotlib.pyplot as plt
section=['A','B','C','D']
studs=[10,20,15,30]
plt.plot(section,studs)
plt.xlabel("section")
plt.ylabel("strength")
plt.title("sectionwise students strength")
plt.grid(True)
plt.yticks(studs)
plt.show()

OUTPUT:

PROGRAM3
import matplotlib.pyplot as plt
x = [1,2,3]
y = [5,7,4]
plt.plot(x,y,label = 'First line')
x2 = [1,2,3]
y2 = [10,11,14]
plt.plot(x2, y2, label = 'Second line')
plt.xlabel('Plot number')
plt.xlabel('Important variables')
plt.title('New Graph')
plt.legend()
plt.show()

OUTPUT:

PRACTICAL IMPLEMENATION 5
import matplotlib.pyplot as plt
import numpy as np
t=np.arange(0.0,20.0,1)
s=[1,2,3,4,5,6,7,8,9,0,11,12,13,14,15,16,17,18,19,20]
s2=[4,5,6,7,8,9,0,11,12,13,14,15,16,17,18,19,20,21,22,23]
plt.subplot(2,1,1)
plt.plot(t,s)
plt.ylabel('value')
plt.title('First chart')
plt.grid(True)
plt.subplot(2,1,2)
plt.plot(t,s2)
plt.xlabel('Item(s)')
plt.ylabel('value')
plt.title('\n\n Second chart')
plt.grid(True)
plt.show()
OUTPUT:

PRACTICAL IMPLEMENATION 7
import matplotlib.pyplot as plt
import numpy as np
xvals = np.arange(-2, 1, 0.01)
yvals = np.sin(xvals)
plt.plot(xvals, yvals)
plt.show()

OUTPUT:
PRACTICAL IMPLEMENATION 8
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(12,20)
y = 10*x+14
plt.title("Graph for an Algebric Expression")
plt.xlabel("x axis")
plt.ylabel("y axis")
plt.plot(x,y)
plt.show()

OUTPUT:
PRACTICAL IMPLEMENATION 9
import matplotlib.pyplot as plt
import numpy as np
xvals = np.arange(-2, 1, 0.01)
newyvals = 1 - 0.5 * xvals**2
plt.plot(xvals, newyvals, 'b--')
plt.title('Example plots')
plt.xlabel('Input')
plt.ylabel('Function Values')
plt.show()

OUTPUT:

PROGRAM10
import matplotlib.pyplot as plt
import numpy as np
y = np.arange(1,3)
plt.plot(y, 'y')
plt.plot(y +1, 'm')
plt.plot(y+2, 'c')
plt.show()
OUTPUT:

PROGRAM11
import matplotlib.pyplot as plt
import pandas as pd
height =
[111.8,120.5,123.4,129.5,134.4,142.5,150.5,152.0,263.7]
weight = [20.5,21.5,24.6,25.8,27.4,30.2,35.2,38.8,45.4]
df = pd.DataFrame({"height":height,"weight":weight})
plt.xlabel('weight in kg')
plt.ylabel('height in cm')
plt.title('average weight vs average height')
plt.plot(df.weight,df.height,marker='*',markersize=10,color='b
linewidth =2,linestyle = 'dashdot')
plt.show()
PROGRAM12
import matplotlib.pyplot as plt
y_axis=[20,50,30]
x_axis = range(len(y_axis))
plt.bar(x_axis,y_axis,width =.5, color = 'orange')
plt.show()

OUTPUT:

PROGRAM13
import matplotlib.pyplot as plt
import numpy as np
objects = ('python','c++','java','perl','scala','lisp')
y_pos = np.arange(len(objects))
performance = [10,8,6,4,2,1]
plt.barh(y_pos,performance,align='center',color = 'r')
plt.yticks(y_pos,objects)
plt.xlabel('usage')
plt.title('PROGRAMming language usage')
plt.show()

OUTPUT:

PROGRAM14
import matplotlib.pyplot as plt
x = [2,4,6,8,10]
y = [6,7,8,2,4]
x2 = [1,3,5,7,9]
y2 = [7,8,2,4,2]
plt.bar(x,y,label='bars1')
plt.bar(x2,y2,label='bars2')
plt.xlabel('x')
plt.ylabel('y')
plt.title('bar graph \n with multiline title')
plt.legend()
plt.show()

OUTPUT:

PROGRAM15
import matplotlib.pyplot as plt
import numpy as np
x=['2015','2016','2017','2018']
y = [82,83,85,90]
plt.bar(x,y)
plt.yticks(np.arange(0,110,10))
plt.ylabel('pass percentage')
plt.xlabel('years')
plt.show()

OUTPUT:
PROGRAM16
import matplotlib.pyplot as plt
import numpy as np
x=['2015','2016','2017','2018']
y = [82,83,85,90]
plt.bar(x,y)
plt.yticks(np.arange(0,110,10))
plt.ylabel('pass percentage')
plt.xlabel('years')
plt.show()
PROGRAM17

import pandas as pd
import matplotlib.pyplot as plt
pltd = pd.Series(index=['A','B','C','D'],data=[10,20,15,30])

pltd.plot(kind = 'bar')
plt.title('sectionwise students strength')
plt.ylabel('strength')
plt.show()

PROGRAM 18
import pandas as pd
import matplotlib.pyplot as plt
pltd = pd.Series(index = ['A','B','C','D'],data=[10,20,15,30])

pltd.plot(kind='bar')
plt.title('sectionwise students strength')
plt.xlabel('sections')
plt.ylabel('strength')
plt.show()
PROGRAM20
import pandas as pd
import matplotlib.pyplot as plt
data={'name':['Anuj','Shruti','Rinku','Vinay','Akaash','Neha']
,
'Height':[60,62,68,66,72,70],
'Weight':[58,60,72,68,80,85]
df=pd.DataFrame(data)
df.plot(kind='hist')
plt.show()
PROGRAM 21

import matplotlib.pyplot as plt


x=[10,15,55,70,10,30,75,89,98,81]
plt.hist(x,bins=5)
plt.show()
PROGRAM 22

import matplotlib.pyplot as plt


import numpy as np
y = np.random.randn(1000)
plt.hist(y)
plt.show()

PROGRAM 23

import matplotlib.pyplot as plt


import numpy as np
y = np.random.randn(1000)
plt.hist(y,25)
plt.show()

PROGRAM 24

import matplotlib.pyplot as plt


import numpy as np
y = np.random.randn(1000)
plt.hist(y,25,edgecolor="red")
plt.show()
PROGRAM 25
import matplotlib.pyplot as plt
student_weight=[19,25,30,35,45,55,60]
plt.hist(student_weight,bins=[0,10,20,30,40,50,60],weights=[20
,10,15,35,40,6,8],
edgecolor='red')
plt.show()
MYSQL PRACTICAL QUESTIONS
QUESTION 24)
mysql> USE kashish;
Database changed
mysql> Create table TEACHERS( ID int, Name varchar(25),
Department varchar(20), Hiredate date, Category varchar(3),
Gender varchar(1), Salary int);
Query OK, 0 rows affected (0.02 sec)

mysql> insert into TEACHERS values( 1, "Tanya Sharma",


"SocialStudies", "1994-03-17", "TGT", "F", 25000);
Query OK, 1 row affected (0.01 sec)

mysql> insert into TEACHERS values(2, 'Saurabh Sharma', 'Art',


'1990-02-12', 'PRT', 'M', 20000);
Query OK, 1 row affected (0.01 sec)

mysql> insert into TEACHERS values(3, 'Nandita Arora',


'English', '1980-05-16', 'PGT', 'F', 30000);
Query OK, 1 row affected (0.01 sec)

mysql> insert into TEACHERS values(4, 'James Jacob',


'English', '1989-10-16', 'TGT', 'M', 25000);
Query OK, 1 row affected (0.01 sec)

mysql> insert into TEACHERS values(5, 'Jaspreet Kaur',


'Hindi', '1990-08-01', 'PRT', 'F', 22000);
Query OK, 1 row affected (0.01 sec)

mysql> insert into TEACHERS values(6, 'Disha Sehgal', 'Math',


'1980-03-17', 'PRT', 'F', 21000);
Query OK, 1 row affected (0.01 sec)
mysql> insert into TEACHERS values(7, 'Sonali Mukherjee',
'Math', '1980-11-17', 'TGT', 'F', 24500);
Query OK, 1 row affected (0.00 sec)

OUTPUT:
mysql> Select * from TEACHERS where Category= 'PGT';
+------+---------------+------------+------------+----------+-
-------+--------+
| ID | Name | Department | Hiredate | Category |
Gender | Salary |
+------+---------------+------------+------------+----------+-
-------+--------+
| 3 | Nandita Arora | English | 1980-05-16 | PGT |
F | 30000 |
+------+---------------+------------+------------+----------+-
-------+--------+
1 row in set (0.03 sec)

mysql> Select Name from TEACHERS where Gender = 'F' and


Department = 'Hindi';
+---------------+
| Name |
+---------------+
| Jaspreet Kaur |
+---------------+
1 row in set (0.00 sec)

mysql> Select Name, Department, Hiredate from TEACHERS order


by Hiredate;
+------------------+---------------+------------+
| Name | Department | Hiredate |
+------------------+---------------+------------+
| Disha Sehgal | Math | 1980-03-17 |
| Nandita Arora | English | 1980-05-16 |
| Sonali Mukherjee | Math | 1980-11-17 |
| James Jacob | English | 1989-10-16 |
| Saurabh Sharma | Art | 1990-02-12 |
| Jaspreet Kaur | Hindi | 1990-08-01 |
| Tanya Sharma | SocialStudies | 1994-03-17 |
+------------------+---------------+------------+
7 rows in set (0.04 sec)

mysql> Select count(*) from TEACHERS where Department =


'English';
+----------+
| count(*) |
+----------+
| 2 |
+----------+
1 row in set (0.01 sec)

mysql> Select Department , Hiredate from TEACHERS where


Gender = 'F' and Salary > 25000;
+------------+------------+
| Department | Hiredate |
+------------+------------+
| English | 1980-05-16 |
+------------+------------+
1 row in set (0.01 sec)

mysql> Select * from TEACHERS where Name like 'J%';


+------+---------------+------------+------------+----------+-
-------+--------+
| ID | Name | Department | Hiredate | Category |
Gender | Salary |
+------+---------------+------------+------------+----------+-
-------+--------+
| 4 | James Jacob | English | 1989-10-16 | TGT |
M | 25000 |
| 5 | Jaspreet Kaur | Hindi | 1990-08-01 | PRT |
F | 22000 |
+------+---------------+------------+------------+----------+-
-------+--------+
2 rows in set (0.01 sec)

mysql> SELECT COUNT(*) FROM TEACHERS where Category = 'PGT';


+----------+
| COUNT(*) |
+----------+
| 1 |
+----------+
1 row in set (0.00 sec)

mysql> SELECT AVG(Salary) from TEACHERS group by Gender;


+-------------+
| AVG(Salary) |
+-------------+
| 24500.0000 |
| 22500.0000 |
+-------------+
2 rows in set (0.02 sec)

QUESTION 25)
mysql> USE kashish;
Database changed
mysql> create table sports(StudentNo int, Class int, Name
varchar(20), Game1 varchar(15), Grade1 varchar(1), Game2
varchar(20), Grade2 varchar(1));
Query OK, 0 rows affected (0.02 sec)

mysql> insert into sports values(10, 7, 'Sameer', 'Cricket',


'B', 'Swimming', 'A');
Query OK, 1 row affected (0.01 sec)

mysql> insert into sports values(11, 8, 'Sujit', 'Tennis',


'A', 'Skating', 'C');
Query OK, 1 row affected (0.01 sec)

mysql> insert into sports values(12, 7, 'Kamal', 'Swimming',


'B', 'Football', 'B');
Query OK, 1 row affected (0.01 sec)

mysql> insert into sports values(13, 7, 'Veena', 'Tennis',


'C', 'Tennis', 'A');
Query OK, 1 row affected (0.01 sec)

mysql> insert into sports values(14, 9, 'Archana',


'Basketball', 'A', 'Cricket', 'A');
Query OK, 1 row affected (0.01 sec)

mysql> insert into sports values(15, 10, 'Arpit', 'Cricket',


'A', 'Athletics', 'C');
Query OK, 1 row affected (0.01 sec)

mysql> Select Name from sports where Grade1 = "c" or Grade2 =


"c";
+-------+
| Name |
+-------+
| Sujit |
| Veena |
| Arpit |
+-------+
3 rows in set (0.00 sec)

mysql> Select count(*) from sports where Game1 = 'Cricket' or


Game2 = 'Cricket';
+----------+
| count(*) |
+----------+
| 3 |
+----------+
1 row in set (0.00 sec)

mysql> Select Name from sports where Game1 = Game2;


+-------+
| Name |
+-------+
| Veena |
+-------+
1 row in set (0.00 sec)

mysql> Select Game1, Game2 from sports where Name like 'A%';
+------------+-----------+
| Game1 | Game2 |
+------------+-----------+
| Basketball | Cricket |
| Cricket | Athletics |
+------------+-----------+
2 rows in set (0.00 sec)

mysql> select count(*) from sports;


+----------+
| count(*) |
+----------+
| 6 |
+----------+
1 row in set (0.02 sec)

mysql> select distinct Class from sports;


+-------+
| Class |
+-------+
| 7 |
| 8 |
| 9 |
| 10 |
+-------+
4 rows in set (0.00 sec)

mysql> select max(Class) from sports;


+------------+
| max(Class) |
+------------+
| 10 |
+------------+
1 row in set (0.01 sec)

mysql> select count(*) from sports group by Game1;


+----------+
| count(*) |
+----------+
| 2 |
| 2 |
| 1 |
| 1 |
+----------+
4 rows in set (0.00 sec)

QUESTION 26)
mysql> USE kashish;
Database changed
mysql> Create table ITEM( IteamNo int, Iname varchar(20),
Price int, Quantity int);
Query OK, 0 rows affected (0.02 sec)

mysql> insert into ITEM values(101, 'Soap', 50, 100);


Query OK, 1 row affected (0.01 sec)

mysql> insert into ITEM values(102, 'Powder', 100, 50);


Query OK, 1 row affected (0.01 sec)

mysql> insert into ITEM values(103, 'Face cream', 150, 25);


Query OK, 1 row affected (0.01 sec)

mysql> insert into ITEM values(104, 'Pen', 50, 200);


Query OK, 1 row affected (0.00 sec)

mysql> insert into ITEM values(105, 'Soap box', 20, 100);


Query OK, 1 row affected (0.01 sec)

mysql> SELECT * FROM ITEM;


+---------+------------+-------+----------+
| IteamNo | Iname | Price | Quantity |
+---------+------------+-------+----------+
| 101 | Soap | 50 | 100 |
| 102 | Powder | 100 | 50 |
| 103 | Face cream | 150 | 25 |
| 104 | Pen | 50 | 200 |
| 105 | Soap box | 20 | 100 |
+---------+------------+-------+----------+
5 rows in set (0.00 sec)

mysql> SELECT Iname, Price FROM ITEM;


+------------+-------+
| Iname | Price |
+------------+-------+
| Soap | 50 |
| Powder | 100 |
| Face cream | 150 |
| Pen | 50 |
| Soap box | 20 |
+------------+-------+
5 rows in set (0.00 sec)

mysql> SELECT * FROM ITEM WHERE Iname = 'Soap';


+---------+-------+-------+----------+
| IteamNo | Iname | Price | Quantity |
+---------+-------+-------+----------+
| 101 | Soap | 50 | 100 |
+---------+-------+-------+----------+
1 row in set (0.00 sec)

mysql> SELECT * FROM ITEM WHERE Iname LIKE 's%';


+---------+----------+-------+----------+
| IteamNo | Iname | Price | Quantity |
+---------+----------+-------+----------+
| 101 | Soap | 50 | 100 |
| 105 | Soap box | 20 | 100 |
+---------+----------+-------+----------+
2 rows in set (0.00 sec)

mysql> SELECT Itemno, Iname, (Price * Quantity) AS TotalPrice


FROM ITEM;
ERROR 1054 (42S22): Unknown column 'Itemno' in 'field list'
mysql> SELECT ItemNo, Iname, (Price * Quantity) AS TotalPrice
FROM ITEM;
ERROR 1054 (42S22): Unknown column 'ItemNo' in 'field list'
mysql> SELECT IteamNo, Iname, (Price * Quantity) AS TotalPrice
FROM ITEM;
+---------+------------+------------+
| IteamNo | Iname | TotalPrice |
+---------+------------+------------+
| 101 | Soap | 5000 |
| 102 | Powder | 5000 |
| 103 | Face cream | 3750 |
| 104 | Pen | 10000 |
| 105 | Soap box | 2000 |
+---------+------------+------------+
5 rows in set (0.01 sec)

mysql> SELECT DISTINCT Price FROM ITEM;


+-------+
| Price |
+-------+
| 50 |
| 100 |
| 150 |
| 20 |
+-------+
4 rows in set (0.00 sec)

mysql> SELECT COUNT(DISTINCT Price) FROM ITEM;


+-----------------------+
| COUNT(DISTINCT Price) |
+-----------------------+
| 4 |
+-----------------------+
1 row in set (0.01 sec)

QUESTION 27)
mysql> SELECT POW(2,3);
+----------+
| POW(2,3) |
+----------+
| 8 |
+----------+
1 row in set (0.01 sec)

mysql> SELECT ROUND(123.2345, 2), ROUND(342.9234, -1);


+--------------------+---------------------+
| ROUND(123.2345, 2) | ROUND(342.9234, -1) |
+--------------------+---------------------+
| 123.23 | 340 |
+--------------------+---------------------+
1 row in set (0.01 sec)
mysql> SELECT LENGTH("Informatics Practices");
+---------------------------------+
| LENGTH("Informatics Practices") |
+---------------------------------+
| 21 |
+---------------------------------+
1 row in set (0.01 sec)

mysql> SELECT LEFT("INDIA",3), RIGHT("Computer Science",4);


+-----------------+-----------------------------+
| LEFT("INDIA",3) | RIGHT("Computer Science",4) |
+-----------------+-----------------------------+
| IND | ence |
+-----------------+-----------------------------+
1 row in set (0.01 sec)

mysql> SELECT MID("Informatics", 3, 4), SUBSTR("Practices",


3);
+--------------------------+------------------------+
| MID("Informatics", 3, 4) | SUBSTR("Practices", 3) |
+--------------------------+------------------------+
| form | actices |
+--------------------------+------------------------+
1 row in set (0.01 sec)

mysql> SELECT CONCAT("You Scored", LENGTH("123"), "rank");


+---------------------------------------------+
| CONCAT("You Scored", LENGTH("123"), "rank") |
+---------------------------------------------+
| You Scored3rank |
+---------------------------------------------+
1 row in set (0.01 sec)

mysql> SELECT ABS(-67.89);


+-------------+
| ABS(-67.89) |
+-------------+
| 67.89 |
+-------------+
1 row in set (0.01 sec)

mysql> SELECT SQRT(625) + ROUND(1234.89, -3);


+--------------------------------+
| SQRT(625) + ROUND(1234.89, -3) |
+--------------------------------+
| 1025 |
+--------------------------------+
1 row in set (0.01 sec)

mysql> SELECT MOD(56,8);


+-----------+
| MOD(56,8) |
+-----------+
| 0 |
+-----------+
1 row in set (0.01 sec)

You might also like