practical file informatics practices 2020-2021

58
In [ ]: ''' LAB ASSIGNMENTS XII - INFORMATICS PRACTICES 2020-21 ''' In [ ]: """ About Python Python language is named after the BBC show “Monty Python’s Flying Circus” and has nothing to do with reptiles.Since the best way to learn a language is to use it, the video invites you to play with the Python Interpreter as you watch. Python was created in the early 1990s by Guido van Rossum as a successor of a language called ABC.In 2001, the Python Software Foundation was formed, a non-profit organization created specifically to own Python-related Intellectual Property. """ PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i... 1 of 58 28-Jan-21, 7:14 PM

Upload: others

Post on 11-Nov-2021

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [ ]: '''LAB ASSIGNMENTS XII - INFORMATICS PRACTICES 2020-21'''

In [ ]: """About Python Python language is named after the BBC show “Monty Python’s Flying Circus”and has nothing to do with reptiles.Since the best way to learn a languageis to use it, the video invites you to play with the Python Interpreteras you watch.

Python was created in the early 1990s by Guido van Rossum as a successorof a language called ABC.In 2001, the Python Software Foundation was formed,a non-profit organization created specifically to own Python-related IntellectualProperty."""

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

1 of 58 28-Jan-21, 7:14 PM

Page 2: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [261]: ## Operators and Operands"""Operators are special tokens that represent computations like addition, multiplication and division.The values the operator works on are called operands.The following are all legal Python expressions whose meaning is more or less clear:20 + 32 # 20 and 32 are operants hour - 1 # hours and 1 are operantshour * 60 + minute # hours , 60 and minutes are operantsminute / 60 # minutes and 60 are operants5 ** 2 # 5 and 2 are operants-3 # 3 is an operand (5 + 9) * (15 - 7)"""print(2 + 3)print(2 - 3)print(2 * 3)print(2 ** 3)print(3 ** 2)minutes = 645hours = minutes / 60print(hours)print(7 / 4)print(7 // 4)minutes = 645hours = minutes // 60print(hours)quotient = 7 // 3 # This is the integer division operatorprint(quotient)remainder = 7 % 3print(remainder)total_secs = 7684

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

2 of 58 28-Jan-21, 7:14 PM

Page 3: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

hours = total_secs // 3600secs_still_remaining = total_secs % 3600minutes = secs_still_remaining // 60secs_finally_remaining = secs_still_remaining % 60print(hours)print(secs_still_remaining)print(minutes)print(secs_finally_remaining)print(2 ** 3 ** 2) # the right-most ** operator gets done first!print((2 ** 3) ** 2) # use parentheses to force the order you want!

5-168910.751.751102124848451264

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

3 of 58 28-Jan-21, 7:14 PM

Page 4: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [14]: # Creating a Series Objectimport pandas as pdmySeries = pd.Series([10,20,30])# Creating a Series Object suing custom indexmySeries1 = pd.Series([10,20,30],index=[5,6,7])print(mySeries)print(mySeries1)# Adding two Series Objectsprint(mySeries+mySeries)

0 101 202 30dtype: int645 106 207 30dtype: int640 201 402 60dtype: int64

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

4 of 58 28-Jan-21, 7:14 PM

Page 5: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [37]: # Slicing ánd Mathematical Operations of Seriesimport pandas as pdmySeries = pd.Series()# Blank Seriesprint(mySeries)mySeries1 = pd.Series(range(20,40,2))# Series using range functionprint(mySeries1)# This will display all elements in reverse orderprint(mySeries1[::-1])# This will display elements with index value of 3 to 5print(mySeries1.iloc[3:6])# This will display elements with index value of 3 to 6print(mySeries1.loc[3:6])# This will display all elements except last 4print(mySeries1.head(-4))# This will display all elements except first 4print(mySeries1.tail(-4))# This will display the largest element of the seriesprint(max(mySeries1))# This will display the smallest element of the seriesprint(min(mySeries1))# This will display the number of elements in the seriesprint(len(mySeries1))# This will add 5 to each element of the seriesprint(mySeries1+5)# This will substract 5 from each element of the seriesprint(mySeries1-5)# This will multiply 5 to each element of the seriesprint(mySeries1*5)# This will divide each element of the series by 5print(mySeries1/5)

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

5 of 58 28-Jan-21, 7:14 PM

Page 6: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

Series([], dtype: float64)0 201 222 243 264 285 306 327 348 369 38dtype: int649 388 367 346 325 304 283 262 241 220 20dtype: int643 264 285 30dtype: int643 264 285 306 32dtype: int64

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

6 of 58 28-Jan-21, 7:14 PM

Page 7: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

0 201 222 243 264 285 30dtype: int644 285 306 327 348 369 38dtype: int643820100 251 272 293 314 335 356 377 398 419 43dtype: int640 151 172 193 21

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

7 of 58 28-Jan-21, 7:14 PM

Page 8: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

4 235 256 277 298 319 33dtype: int640 1001 1102 1203 1304 1405 1506 1607 1708 1809 190dtype: int640 4.01 4.42 4.83 5.24 5.65 6.06 6.47 6.88 7.29 7.6dtype: float64

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

8 of 58 28-Jan-21, 7:14 PM

Page 9: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [1]: # Use of header and tail methods of Seriesimport pandas as pdmyDict= {1:'Mannat',2:'Samidha',3:'Jai',4:'Kalk',5:'Abhishek',6:'Yuvesh'}print(myDict)mySeries=pd.Series(myDict)print(mySeries)# By default head() function will print top five elementsprint(mySeries.head())# By default tail() function will print last five elementsprint(mySeries.tail())

{1: 'Mannat', 2: 'Samidha', 3: 'Jai', 4: 'Kalk', 5: 'Abhishek', 6: 'Yuvesh'}1 Mannat2 Samidha3 Jai4 Kalk5 Abhishek6 Yuveshdtype: object1 Mannat2 Samidha3 Jai4 Kalk5 Abhishekdtype: object2 Samidha3 Jai4 Kalk5 Abhishek6 Yuveshdtype: object

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

9 of 58 28-Jan-21, 7:14 PM

Page 10: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [260]: # where condition using Seriesimport pandas as pdmyDict= {1:10,2:20,3:30}myDict2= {1:'Ajay',2:'Dheeraj',3:'Shanku'}print(myDict)mySeries=pd.Series(myDict)mySeries2=pd.Series(myDict2)print(mySeries)# Simple where conditionprint(mySeries.where(mySeries > 10))print(mySeries.where(mySeries < 20))print(mySeries.where(mySeries == 10))#The where() function is used to replace values where the condition is False.print(mySeries.where(mySeries == 10,33))#The where() function is used to replace values where the condition is False.print(mySeries.where(mySeries != 10,33))print(mySeries2)# Simple where conditionprint(mySeries2.where(mySeries2 == 'Ajay'))print(mySeries2.where(mySeries2 != 'Ajay'))#The where() function is used to replace values where the condition is False.print(mySeries2.where(mySeries2 == 'Ajay','Akshay'))

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

10 of 58 28-Jan-21, 7:14 PM

Page 11: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

{1: 10, 2: 20, 3: 30}1 102 203 30dtype: int641 NaN2 20.03 30.0dtype: float641 10.02 NaN3 NaNdtype: float641 10.02 NaN3 NaNdtype: float641 102 333 33dtype: int641 332 203 30dtype: int641 Ajay2 Dheeraj3 Shankudtype: object1 Ajay2 NaN3 NaN

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

11 of 58 28-Jan-21, 7:14 PM

Page 12: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [17]: # DataFrame in Python programming Languageimport pandas as pdmyList = [10,20,30,40]# Creating a DataFrame with list and custom column name/indexmyDataFrame = pd.DataFrame(myList,columns=['Roll No'])print(myDataFrame)myBlankDataFrame= pd.DataFrame()# Blank DataFrameprint(myBlankDataFrame)

dtype: object1 NaN2 Dheeraj3 Shankudtype: object1 Ajay2 Akshay3 Akshaydtype: object

Roll No0 101 202 303 40Empty DataFrameColumns: []Index: []

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

12 of 58 28-Jan-21, 7:14 PM

Page 13: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [18]: # DataFrame with custom column name/indeximport pandas as pdmyList = [['Ashima',12],['Mannat',14],['Samidha',15],['Jai',16]]myDataFrame = pd.DataFrame(myList,columns=['Name','Roll No'])print(myDataFrame)

Name Roll No0 Ashima 121 Mannat 142 Samidha 153 Jai 16

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

13 of 58 28-Jan-21, 7:14 PM

Page 14: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [22]: # Use of isnull and notnull in DataFrameimport pandas as pdmyList = [['Ashima',12],['Mannat'],['Samidha',15],['Jai']]myDataFrame = pd.DataFrame(myList,columns=['Name','Roll No'])#Pandas isnull() method is used to check NULL values in a data frame.print(myDataFrame.isnull())#Method 1print(pd.isnull(myDataFrame)) # Method 2#Pandas notnull() method is used to check NOT NULL values in a data frame.print(myDataFrame.notnull())#Method 1print(pd.notnull(myDataFrame)) # Method 2

Name Roll No0 False False1 False True2 False False3 False True Name Roll No0 False False1 False True2 False False3 False True Name Roll No0 True True1 True False2 True True3 True False Name Roll No0 True True1 True False2 True True3 True False

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

14 of 58 28-Jan-21, 7:14 PM

Page 15: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [45]: # DataFrame using Dictionary in Python programming Languageimport pandas as pdmyDict = {'Name':['Ashima','Mannat','Samidha'],'Roll No':[14,15,16]}myDataFrame = pd.DataFrame(myDict)print(myDataFrame)

Name Roll No0 Ashima 141 Mannat 152 Samidha 16

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

15 of 58 28-Jan-21, 7:14 PM

Page 16: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [81]: # Slicing of DataFrameimport pandas as pdmyDict = {'Name':['Ashima','Mannat','Samidha'],'Roll No':[14,15,16]}myDataFrame = pd.DataFrame(myDict,index=['Row 1','Row 2','Row 3'])print(myDataFrame)print(myDataFrame[1:3])print(myDataFrame[0:3:2])print(myDataFrame[:3])print(myDataFrame[2:])print(myDataFrame[:])print(myDataFrame[::2])print(myDataFrame[::-1])print(myDataFrame['Name'])print(myDataFrame['Roll No'])print(myDataFrame[0:1])# Adding new column in the DataFramemyDataFrame['Age']=[15,15,16]print(myDataFrame)

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

16 of 58 28-Jan-21, 7:14 PM

Page 17: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

Name Roll NoRow 1 Ashima 14Row 2 Mannat 15Row 3 Samidha 16 Name Roll NoRow 2 Mannat 15Row 3 Samidha 16 Name Roll NoRow 1 Ashima 14Row 3 Samidha 16 Name Roll NoRow 1 Ashima 14Row 2 Mannat 15Row 3 Samidha 16 Name Roll NoRow 3 Samidha 16 Name Roll NoRow 1 Ashima 14Row 2 Mannat 15Row 3 Samidha 16 Name Roll NoRow 1 Ashima 14Row 3 Samidha 16 Name Roll NoRow 3 Samidha 16Row 2 Mannat 15Row 1 Ashima 14Row 1 AshimaRow 2 MannatRow 3 SamidhaName: Name, dtype: objectRow 1 14

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

17 of 58 28-Jan-21, 7:14 PM

Page 18: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

Row 2 15Row 3 16Name: Roll No, dtype: int64 Name Roll NoRow 1 Ashima 14 Name Roll No AgeRow 1 Ashima 14 15Row 2 Mannat 15 15Row 3 Samidha 16 16

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

18 of 58 28-Jan-21, 7:14 PM

Page 19: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [35]: # Inserting new coulmn and updating exisitng column in DataFrameimport pandas as pdmyDict = {'Subject':['Accountancy','Business','Economics','English','IP'],'Marks':[78,67,90,79,89]}myDataFrame = pd.DataFrame(myDict)print(myDataFrame)# Adding new column in the DataFramemyDataFrame['Percentage']=myDataFrame['Marks']/90*100print(myDataFrame)# Adding new column in the DataFrame using loc methodmyDataFrame.loc[:,'Attendance']=['P','P','P','P','P']print(myDataFrame)# Updating Marks columnmyDataFrame['Marks']=myDataFrame['Marks']+5print(myDataFrame)# Updating Percentage columnmyDataFrame['Percentage']=myDataFrame['Marks']/95*100print(myDataFrame)# Adding new column in the DataFrame using locmyDataFrame.loc[:,'Attendance']=['P','P','P','P','P']print(myDataFrame)

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

19 of 58 28-Jan-21, 7:14 PM

Page 20: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

Subject Marks0 Accountancy 781 Business 672 Economics 903 English 794 IP 89 Subject Marks Percentage0 Accountancy 78 86.6666671 Business 67 74.4444442 Economics 90 100.0000003 English 79 87.7777784 IP 89 98.888889 Subject Marks Percentage Attendance0 Accountancy 78 86.666667 P1 Business 67 74.444444 P2 Economics 90 100.000000 P3 English 79 87.777778 P4 IP 89 98.888889 P Subject Marks Percentage Attendance0 Accountancy 83 86.666667 P1 Business 72 74.444444 P2 Economics 95 100.000000 P3 English 84 87.777778 P4 IP 94 98.888889 P Subject Marks Percentage Attendance0 Accountancy 83 87.368421 P1 Business 72 75.789474 P2 Economics 95 100.000000 P3 English 84 88.421053 P4 IP 94 98.947368 P Subject Marks Percentage Attendance0 Accountancy 83 87.368421 P

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

20 of 58 28-Jan-21, 7:14 PM

Page 21: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [114]: # Use of iloc method of DataFrame

import pandas as pdmyDict = {'Name':['Ashima','Mannat','Samidha'],'Roll No':[14,15,16]}myDataFrame = pd.DataFrame(myDict,index=['Row 1','Row 2','Row 3'])print(myDataFrame)print(myDataFrame.iloc[0:2,[0,1]])print(myDataFrame.iloc[-3:-1,[0,1]])print(myDataFrame.iloc[0,[1]])

1 Business 72 75.789474 P2 Economics 95 100.000000 P3 English 84 88.421053 P4 IP 94 98.947368 P

Name Roll NoRow 1 Ashima 14Row 2 Mannat 15Row 3 Samidha 16 Name Roll NoRow 1 Ashima 14Row 2 Mannat 15 Name Roll NoRow 1 Ashima 14Row 2 Mannat 15Roll No 14Name: Row 1, dtype: object

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

21 of 58 28-Jan-21, 7:14 PM

Page 22: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [115]: # Deletion operation on DataFrame using delimport pandas as pdmyDict = {'Name':['Ashima','Mannat','Samidha'],'Roll No':[14,15,16]}myDataFrame = pd.DataFrame(myDict,index=['Row 1','Row 2','Row 3'])print(myDataFrame)del(myDataFrame['Roll No']) # In-place deletionprint(myDataFrame)myDataFrame.drop('Roll No',axis])

Name Roll NoRow 1 Ashima 14Row 2 Mannat 15Row 3 Samidha 16 NameRow 1 AshimaRow 2 MannatRow 3 Samidha

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

22 of 58 28-Jan-21, 7:14 PM

Page 23: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [130]: # Deletion operation on DataFrame using dropimport pandas as pdmyDict = {'Name':['Ashima','Mannat','Samidha'],'Roll No':[14,15,16]}myDataFrame = pd.DataFrame(myDict,index=['Row 1','Row 2','Row 3'])print(myDataFrame)updatedDataFrame=myDataFrame.drop('Roll No',axis=1)# Not In-place deletionprint(myDataFrame)print(updatedDataFrame)updatedDataFrame=myDataFrame.drop('Row 2',axis=0)# Not In-place deletionprint(updatedDataFrame)

Name Roll NoRow 1 Ashima 14Row 2 Mannat 15Row 3 Samidha 16 Name Roll NoRow 1 Ashima 14Row 2 Mannat 15Row 3 Samidha 16 NameRow 1 AshimaRow 2 MannatRow 3 Samidha Name Roll NoRow 1 Ashima 14Row 3 Samidha 16

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

23 of 58 28-Jan-21, 7:14 PM

Page 24: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [132]: # Deletion operation on DataFrame using popimport pandas as pdmyDict = {'Name':['Ashima','Mannat','Samidha'],'Roll No':[14,15,16]}myDataFrame = pd.DataFrame(myDict,index=['Row 1','Row 2','Row 3'])print(myDataFrame)myDataFrame.pop('Roll No')# In-place deletionprint(myDataFrame)

Name Roll NoRow 1 Ashima 14Row 2 Mannat 15Row 3 Samidha 16 NameRow 1 AshimaRow 2 MannatRow 3 Samidha

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

24 of 58 28-Jan-21, 7:14 PM

Page 25: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [165]: # Arithmetic operations on DataFrameimport pandas as pdmyDict = {'Roll No':[14,15,16]}myDataFrame = pd.DataFrame(myDict,index=['Row 1','Row 2','Row 3'])print(myDataFrame+5)print(myDataFrame-5)print(myDataFrame*5)print(myDataFrame/5)print(myDataFrame)

Roll NoRow 1 19Row 2 20Row 3 21 Roll NoRow 1 9Row 2 10Row 3 11 Roll NoRow 1 70Row 2 75Row 3 80 Roll NoRow 1 2.8Row 2 3.0Row 3 3.2 Roll NoRow 1 14Row 2 15Row 3 16

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

25 of 58 28-Jan-21, 7:14 PM

Page 26: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [146]: # Binary/Arithmetic operations using inbuilt methods on DataFrameimport pandas as pdmyDict = {'Marks 1':[14,15,16],'Marks 2':[7,9,10]}myDict2 = {'Marks 1':[12,13,10],'Marks 2':[4,8,9]}myDataFrame = pd.DataFrame(myDict)myDataFrame2 = pd.DataFrame(myDict2)print(myDataFrame)print(myDataFrame2)print(myDataFrame.add(myDataFrame2))print(myDataFrame.sub(myDataFrame2))print(myDataFrame.mul(myDataFrame2))

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

26 of 58 28-Jan-21, 7:14 PM

Page 27: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

Marks 1 Marks 20 14 71 15 92 16 10 Marks 1 Marks 20 12 41 13 82 10 9 Marks 1 Marks 20 26 111 28 172 26 19 Marks 1 Marks 20 2 31 2 12 6 1 Marks 1 Marks 20 168 281 195 722 160 90

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

27 of 58 28-Jan-21, 7:14 PM

Page 28: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [40]: # Use of min,max,sum,count,mode,mean,median on DataFrameimport pandas as pdmyDict = {'Marks 1':[14,15,6],'Marks 2':[7,9,10]}myDataFrame = pd.DataFrame(myDict)print(myDataFrame)# This will display the maximum element in the DataFrame Column wise.print(myDataFrame.max()) # Default axis =0 means Column wise# This will display the maximum element in the DataFrame Row Wise.print(myDataFrame.max(axis=1))# axis =1 means Row wise# This will display the maximum element of Marks 1 column.print(myDataFrame['Marks 1'].max())# This will display the minimum element in the DataFrame Column wise.print(myDataFrame.min())# This will display the minimum element in the DataFrame Row Wise.print(myDataFrame.min(axis=1))# This will display the minimum element of Marks 1 column.print(myDataFrame['Marks 1'].min())# This will display the sum of all element column wise.print(myDataFrame.sum())# This will display the sum of all element row wise.print(myDataFrame.sum(axis=1))# This will display the sum of all element Marks 1 column.print(myDataFrame['Marks 1'].sum())# This will display number of elements column wise.print(myDataFrame.count())# This will display number of elements row wise.print(myDataFrame.count(axis=1))# This will display number of elements in Marks 1 column.print(myDataFrame['Marks 1'].count())# This will display mode of elements column wise.print(myDataFrame.mode())# This will display mode of elements row wise.

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

28 of 58 28-Jan-21, 7:14 PM

Page 29: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

print(myDataFrame.mode(axis=1))# This will display mode of Marks 1 column.print(myDataFrame['Marks 1'].mode())# This will display mean of elements column wise.print(myDataFrame.mean())# This will display mean of elements row wise.print(myDataFrame.mean(axis=1))# This will display mean of Marks 1 column.print(myDataFrame['Marks 1'].mean())# This will display median of elements column wise.print(myDataFrame.median())# This will display median of elements row wise.print(myDataFrame.median(axis=1))# This will display median of Marks 1 column.print(myDataFrame['Marks 1'].median())# This will display median columns name.print(myDataFrame.columns)# This will display median index values.print(myDataFrame.index)# This will display total number of rows in DataFrame.print(len(myDataFrame))

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

29 of 58 28-Jan-21, 7:14 PM

Page 30: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

Marks 1 Marks 20 14 71 15 92 6 10Marks 1 15Marks 2 10dtype: int640 141 152 10dtype: int6415Marks 1 6Marks 2 7dtype: int640 71 92 6dtype: int646Marks 1 35Marks 2 26dtype: int640 211 242 16dtype: int6435Marks 1 3Marks 2 3dtype: int640 2

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

30 of 58 28-Jan-21, 7:14 PM

Page 31: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

1 22 2dtype: int643 Marks 1 Marks 20 6 71 14 92 15 10 0 10 7 141 9 152 6 100 61 142 15dtype: int64Marks 1 11.666667Marks 2 8.666667dtype: float640 10.51 12.02 8.0dtype: float6411.666666666666666Marks 1 14.0Marks 2 9.0dtype: float640 10.51 12.02 8.0dtype: float6414.0

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

31 of 58 28-Jan-21, 7:14 PM

Page 32: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [41]: # Copying a Column to create a new Column in DataFrameimport pandas as pdmyDict = {'Roll No':[14,15,16]}myDataFrame = pd.DataFrame(myDict,index=['Row 1','Row 2','Row 3'])print(myDataFrame)# Creating new column from exisitng column datamyDataFrame['Admission No']= myDataFrame['Roll No']print(myDataFrame)# Creating new column directlymyDataFrame['Age']= [17,15,18]print(myDataFrame)

Index(['Marks 1', 'Marks 2'], dtype='object')RangeIndex(start=0, stop=3, step=1)3

Roll NoRow 1 14Row 2 15Row 3 16 Roll No Admission NoRow 1 14 14Row 2 15 15Row 3 16 16 Roll No Admission No AgeRow 1 14 14 17Row 2 15 15 15Row 3 16 16 18

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

32 of 58 28-Jan-21, 7:14 PM

Page 33: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [45]: # Renaming a Column in DataFrameimport pandas as pdmyDict = {'Roll No':[14,15,16],'Age':[14,15,16]}myDataFrame = pd.DataFrame(myDict,index=['Row 1','Row 2','Row 3'])print(myDataFrame)# Renaming Column Roll No to Admission NomyDataFrame.rename(columns ={'Roll No':'Admission No'},inplace=True)print(myDataFrame)

Roll No AgeRow 1 14 14Row 2 15 15Row 3 16 16 Admission No AgeRow 1 14 14Row 2 15 15Row 3 16 16

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

33 of 58 28-Jan-21, 7:14 PM

Page 34: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [46]: # Custom Head and Tail function in DataFrameimport pandas as pdmyDict = {'Roll No':[7,8,9],'Age':[14,15,16]}myDataFrame = pd.DataFrame(myDict,index=['Row 1','Row 2','Row 3'])print(myDataFrame)# Thsi will display top 2 elementsprint(myDataFrame.head(2))# Thsi will display last 2 elementsprint(myDataFrame.tail(2))

Roll No AgeRow 1 7 14Row 2 8 15Row 3 9 16 Roll No AgeRow 1 7 14Row 2 8 15 Roll No AgeRow 2 8 15Row 3 9 16

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

34 of 58 28-Jan-21, 7:14 PM

Page 35: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [188]: # Concatenation row and column wise in DataFrameimport pandas as pdmyDict = {'Marks 1':[14,15,16],'Marks 2':[7,9,10]}myDict2 = {'Marks 1':[12,13,10],'Marks 2':[4,8,9]}myDataFrame = pd.DataFrame(myDict)myDataFrame2 = pd.DataFrame(myDict2)print(myDataFrame)print(myDataFrame2)# Combining two exisitng dataFrames to form a new dataFrame row wisemyDataFrame3 = pd.concat([myDataFrame,myDataFrame2],axis=0)print(myDataFrame3)# Combining two exisitng dataFrames to form a new dataFrame column wisemyDataFrame3 = pd.concat([myDataFrame,myDataFrame2],axis=1)print(myDataFrame3)

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

35 of 58 28-Jan-21, 7:14 PM

Page 36: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

Marks 1 Marks 20 14 71 15 92 16 10 Marks 1 Marks 20 12 41 13 82 10 9 Marks 1 Marks 20 14 71 15 92 16 100 12 41 13 82 10 9 Marks 1 Marks 2 Marks 1 Marks 20 14 7 12 41 15 9 13 82 16 10 10 9

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

36 of 58 28-Jan-21, 7:14 PM

Page 37: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [50]: # Joining/Merging two Dataframes# This is same as SQL join operationimport pandas as pdmyDict = {'Marks 1':[14,15,16],'Marks 2':[7,9,10]}myDict2 = {'Marks 1':[14,15,10],'Marks 2':[4,8,9]}myDataFrame = pd.DataFrame(myDict)myDataFrame2 = pd.DataFrame(myDict2)print(myDataFrame)print(myDataFrame2)# Joining two exisitng DataFrames on Marks 1 column myDataFrame3 = pd.merge(myDataFrame,myDataFrame2,on='Marks 1')print(myDataFrame3)# Joining two exisitng DataFrames on Marks 2 column myDataFrame3 = pd.merge(myDataFrame,myDataFrame2,on='Marks 2')print(myDataFrame3)

Marks 1 Marks 20 14 71 15 92 16 10 Marks 1 Marks 20 14 41 15 82 10 9 Marks 1 Marks 2_x Marks 2_y0 14 7 41 15 9 8 Marks 1_x Marks 2 Marks 1_y0 15 9 10

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

37 of 58 28-Jan-21, 7:14 PM

Page 38: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [198]: # Boolean Indexing on Dataframeimport pandas as pdmyDict = {'Marks 1':[14,15,16],'Marks 2':[7,9,10]}# Use of Boolean IndexmyDataFrame = pd.DataFrame(myDict,index = [True,False,True])print(myDataFrame)

Marks 1 Marks 2True 14 7False 15 9True 16 10

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

38 of 58 28-Jan-21, 7:14 PM

Page 39: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [52]: # Iteration over Rows and Columnimport pandas as pdmyDict = {'Marks 1':[14,15,16],'Marks 2':[7,9,10]}myDataFrame = pd.DataFrame(myDict)print(myDataFrame)# Basic Iterationfor i in myDataFrame.index:

print(myDataFrame['Marks 1'][i],myDataFrame['Marks 2'][i])# Iteration using loc functionfor i in myDataFrame.index:

print(myDataFrame.loc[i,'Marks 1'],myDataFrame.loc[i,'Marks 2'])# Iteration using iloc functionfor i in myDataFrame.index:

print(myDataFrame.iloc[i,0],myDataFrame.iloc[i,1])

Marks 1 Marks 20 14 71 15 92 16 1014 715 916 1014 715 916 1014 715 916 10

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

39 of 58 28-Jan-21, 7:14 PM

Page 40: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [55]: # Creation of DataFrame using CSV file"""CSV File ContentsName,Branch,Year,CGPANikhil,COE,2,9.0Sanchit,COE,2,9.1Aditya,IT,2,9.3Sagar,SE,1,9.5Prateek,MCE,3,7.8"""import pandas as pd# Use of read_csv function of Pandasdata = pd.read_csv ('university_records.csv') df = pd.DataFrame(data, columns= ['Name','Branch','Year','CGPA'])print (df)

Name Branch Year CGPA0 Nikhil COE 2 9.01 Sanchit COE 2 9.12 Aditya IT 2 9.33 Sagar SE 1 9.54 Prateek MCE 3 7.85 Sahil EP 2 9.1

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

40 of 58 28-Jan-21, 7:14 PM

Page 41: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [56]: # Importing/Exporting DataFrame from/to CSV fileimport pandas as pdmyDict = {'Marks 1':[14,15,16],'Marks 2':[7,9,10]}myDataFrame = pd.DataFrame(myDict)print(myDataFrame)myDataFrame.to_csv('my.csv')#Exporting DataFrame data to csv filedata = pd.read_csv ('my.csv')#Importing csv file data#Craeting a DataFrame from Imported csv file datamyDataFrame2=pd.DataFrame(data,columns= ['Marks 1','Marks 2'])print(myDataFrame2)

Marks 1 Marks 20 14 71 15 92 16 10 Marks 1 Marks 20 14 71 15 92 16 10

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

41 of 58 28-Jan-21, 7:14 PM

Page 42: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [31]: # Write Python code to print all the elements that are above the 75th percentile of given series. import pandas as pdmyList=[1,3,4,7,8,8,9]df=pd.Series(myList)# This statement will display the original DataFrameprint(df)# This statement will display elements that are above the 75th percentiles=df[df>= np.percentile(df, 0.75)]print(s)

0 11 32 43 74 85 86 9dtype: int641 32 43 74 85 86 9dtype: int64

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

42 of 58 28-Jan-21, 7:14 PM

Page 43: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [46]: """Create a Data Frame quarterly sales where each row contains the item category,item name, and expenditure.Group the rows by the category and print the totalexpenditure per category."""import pandas as pdmyDict = {'Item category':['Electrical','Stationary','Cloth','Electrical','Cloth'],

'Item name':['Blub','Notebook','Shirt','Tube','Trouser'],'Expenditure' : [500,1000,1500,2000,2500]

}myDataFrame = pd.DataFrame(myDict)# This statement will display the original DataFrameprint(myDataFrame)# Grouping using column name same as SQL Group By clausegroupedDictionary=myDataFrame.groupby('Item category')["Expenditure"].sum()print(groupedDictionary)

Item category Item name Expenditure0 Electrical Blub 5001 Stationary Notebook 10002 Cloth Shirt 15003 Electrical Tube 20004 Cloth Trouser 2500Item categoryCloth 4000Electrical 2500Stationary 1000Name: Expenditure, dtype: int64

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

43 of 58 28-Jan-21, 7:14 PM

Page 44: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [47]: """Create a data frame for examination result and display row labels,column labels data types of each column and the dimensions"""import pandas as pdmyDict = {'Name':['Ayaan','Jatin','Abhay'],

'Result':['Pass','Pass','Pass'],}

myDataFrame = pd.DataFrame(myDict)# This statement will display the original DataFrameprint(myDataFrame)# This statement will display column namesprint(myDataFrame.columns)# This statement will display row namesprint(myDataFrame.index)# This statement will display datatype of each columnprint(myDataFrame.dtypes)# This statement will display dimension of DataFrameprint(myDataFrame.shape)

Name Result0 Ayaan Pass1 Jatin Pass2 Abhay PassIndex(['Name', 'Result'], dtype='object')RangeIndex(start=0, stop=3, step=1)Name objectResult objectdtype: object(3, 2)

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

44 of 58 28-Jan-21, 7:14 PM

Page 45: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [33]: #Filter out rows based on different criteria such as duplicate rows. import pandas as pdmyDict = {'PresentÇity':['Shimla','Palampur','Palampur'],

'NativeCity':['Ambala','Palampur','Palampur'],}

myDataFrame = pd.DataFrame(myDict)# This statement will display the original DataFrameprint(myDataFrame)# This statement will Filter out duplicate rowsprint(myDataFrame.drop_duplicates())

PresentÇity NativeCity0 Shimla Ambala1 Palampur Palampur2 Palampur Palampur PresentÇity NativeCity0 Shimla Ambala1 Palampur Palampur

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

45 of 58 28-Jan-21, 7:14 PM

Page 46: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [226]: # Line plot using matplotlib Libraryimport matplotlib.pyplot as pltlangs = ['C', 'C++', 'Java', 'Python', 'PHP']students = [23,17,35,29,12]line2_x=[1,2,3,4,5,6]line2_y=[1,4,9,14,19,24]plt.xlabel("Language")plt.ylabel("Students")plt.title("Use of Languages")plt.plot(langs,students ,color='k', linestyle='solid',linewidth=10,label='line 1')plt.plot(line2_x,line2_y,color='y',linestyle='dashdot',linewidth=10, label='line 2')plt.legend()plt.show()

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

46 of 58 28-Jan-21, 7:14 PM

Page 47: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [227]: # Bar Graph using matplotlib Libraryimport matplotlib.pyplot as pltlangs = ['C', 'C++', 'Java', 'Python', 'PHP']students = [23,17,35,29,22]plt.xlabel("Language")plt.ylabel("Students")plt.title("Use of Languages")plt.bar(students ,langs ,color='r')plt.show()

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

47 of 58 28-Jan-21, 7:14 PM

Page 48: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [228]: # Ploting Histogram using matplotlib Library'''HistogramsLike a bar chart, a histogram is made up of columns plotted on a graph.Usually,there is no space between adjacent columns.The columns are positioned over a label that represents a continuous,quantitative variable.The column label can be a single value or a range of values.The height of the column indicates the size of the group definedby the column label.'''

import matplotlib.pyplot as plt'''For example, let’s say that you have the followingdata about the age of 50 individuals:'''x = [1,1,2,3,3,5,7,8,9,10,

10,11,11,13,13,15,16,17,18,18,18,19,20,21,21,23,24,24,25,25,25,25,26,26,26,27,27,27,27,27,29,30,30,31,33,34,34,34,35,36,]

plt.xlabel("Age range of 50 Indivisulas")plt.ylabel("No. of Indivisuals")plt.title("Histogram Example")plt.hist(x, bins=30)plt.show()

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

48 of 58 28-Jan-21, 7:14 PM

Page 49: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

49 of 58 28-Jan-21, 7:14 PM

Page 50: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [89]: """Given the school result data, analyses the performance of the studentson different parameters, e.g subject wise or class wise

Using bar plot analysing the performance of the studentssubject wise or class wise"""import matplotlib.pyplot as pltimport pandas as pdSubjectWiseDict= {'Subject Name':['Economics','Accounts','B Study','English','IP'],

'Pass Percentage':[80,78,90,85,100]}SubjectWisePercentage=pd.DataFrame(SubjectWiseDict)print(SubjectWisePercentage)

ClassWiseDict= {'Class Name':['XI C','XII C'],'Pass Percentage':[80,90]}

ClassWisePercentage=pd.DataFrame(ClassWiseDict)print(ClassWisePercentage)

# Subject wise performance# Use of DatFrame's plot.bar methodSubjectWisePercentage.plot.bar(x='Subject Name',y='Pass Percentage',title='Subject wise Performance')plt.show()# Class wise performance# Use of DatFrame's plot.bar methodClassWisePercentage.plot.bar(x='Class Name',y='Pass Percentage',title='Class wise Performance')plt.show()

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

50 of 58 28-Jan-21, 7:14 PM

Page 51: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

Subject Name Pass Percentage0 Economics 801 Accounts 782 B Study 903 English 854 IP 100 Class Name Pass Percentage0 XI C 801 XII C 90

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

51 of 58 28-Jan-21, 7:14 PM

Page 52: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

52 of 58 28-Jan-21, 7:14 PM

Page 53: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [86]: """Given the school result data, analyses the performance of the studentson different parameters, e.g subject wise or class wise

Using line plot analysing the performance of the studentssubject wise or class wise"""

import matplotlib.pyplot as pltimport pandas as pdSubjectWiseDict= {'Subject Name':['Economics','Accounts','B Study','English','IP'],

'Pass Percentage':[80,78,90,85,100]}SubjectWisePercentage=pd.DataFrame(SubjectWiseDict)print(SubjectWisePercentage)

ClassWiseDict= {'Class Name':['XI C','XII C'],'Pass Percentage':[80,90]}

ClassWisePercentage=pd.DataFrame(ClassWiseDict)print(ClassWisePercentage)

# Subject wise performance# Use of DatFrame's plot.line methodSubjectWisePercentage.plot.line(x='Subject Name',y='Pass Percentage',title='Subject wise Performance')plt.show()# Class wise performance# Use of DatFrame's plot.line methodClassWisePercentage.plot.line(x='Class Name',y='Pass Percentage',title='Class wise Performance')plt.show()

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

53 of 58 28-Jan-21, 7:14 PM

Page 54: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

Subject Name Pass Percentage0 Economics 801 Accounts 782 B Study 903 English 854 IP 100 Class Name Pass Percentage0 XI C 801 XII C 90

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

54 of 58 28-Jan-21, 7:14 PM

Page 55: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

55 of 58 28-Jan-21, 7:14 PM

Page 56: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [88]: """Given the school result data, analyses the performance of the studentson different parameters, e.g subject wise or class wise

Using pie plot analysing the performance of the studentssubject wise or class wise"""import matplotlib.pyplot as pltimport pandas as pdSubjectWiseDict= {'Subject Name':['Economics','Accounts','B Study','English','IP'],

'Pass Percentage':[80,78,90,85,100]}SubjectWisePercentage=pd.DataFrame(SubjectWiseDict)print(SubjectWisePercentage)

ClassWiseDict= {'Class Name':['XI C','XII C'],'Pass Percentage':[80,90]}

ClassWisePercentage=pd.DataFrame(ClassWiseDict)print(ClassWisePercentage)

# Subject wise performance# Use of DatFrame's plot.pie methodSubjectWisePercentage.plot.pie(x='Subject Name',y='Pass Percentage',title='Subject wise Performance')plt.show()# Class wise performance# Use of DatFrame's plot.pie methodClassWisePercentage.plot.pie(x='Class Name',y='Pass Percentage',title='Class wise Performance')plt.show()

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

56 of 58 28-Jan-21, 7:14 PM

Page 57: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

Subject Name Pass Percentage0 Economics 801 Accounts 782 B Study 903 English 854 IP 100 Class Name Pass Percentage0 XI C 801 XII C 90

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

57 of 58 28-Jan-21, 7:14 PM

Page 58: PRACTICAL FILE INFORMATICS PRACTICES 2020-2021

In [ ]: """Do these SQL assignments yourself.1. Create a student table with the student id, name, and marksas attributes where the student id is the primary key.2. Insert the details of a new student in the above table.3. Delete the details of a student in the above table.4. Use the select command to get the details of the students with marks more than 80.5. Find the min, max, sum, and average of the marks in a student marks table.6. Find the total number of customers from each country in the table (customer ID, customer Name, country) using group by.7. Write a SQL query to order the (student ID, marks) table in descending order of the marks.

PRACTICAL FILE INFORMATICS PRACTICES 2020-2021 http://localhost:8888/nbconvert/html/PRACTICAL FILE INFORMATICS PRACTICES 2020-2021.i...

58 of 58 28-Jan-21, 7:14 PM