0% found this document useful (0 votes)
260 views31 pages

Ip Practical PDF 2023-24

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
260 views31 pages

Ip Practical PDF 2023-24

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 31
INFORMATICS PRACTICES PRACTICAL EXERCISES 2022-23 CLASS - XII CREATING A SERIES USING DICTIONARY To write a Python program to create a Series to store 5 students Percentage Using dictionary and print all the elements that are above 75 percentage. ‘SOURCE CODE: import pandas as pd ID={"Arun":65,"Bala":91,"Charan":74, "Dinesh" :80, "Usha" :85} 'S=pd. Series (D) print (S[S>75]) RESULT: Thus, the above Python program is executed successfully and the output is verified. SAMPLE OUTPUT: Bala 91 Dinesh 80 Usha 85 dtype: intéea LSet ISR ISSIR ER ISS I SIDI STS SO AIT CREATING A SERIES USING SCALAR VALUE To write a Python program to create a Series object that stores the Initial budget allocated (50000/- each) for the four quarters of the year: Qtrl, Qtr2, Qtr3 and Qtr4. SOURCE CODE: import pandas as pd Budget=pd. Series (50000, index=['Qtr1', 'Qtr2', 'Qtr3', 'Qtr4']) print (Budget) RESULT: Thus, the above Python program is executed successfully and the output is verified. SAMPLE OUPUT: Qtr1 50000 Qtr2 50000 gtr3 50000 gtr4 — 50000 dtype: int64 CREATING A SERIES USING NUMPY ARRAY AIM: To write a Python program to create a Series object that stores the Section names (A‘'B,'C) as the index and Contribution made by them respectively (6700,5500,nil) as values. SOURCE CODE: Contribution=np. array ([6700, 5500, np.NaN]) \s=pd. Series (data=contribution, index=section) lprint (s) RESULT: Thus, the above Python program is executed successfully and the output is verified. SAMPLE OUTPUT; A 6700.0 B 5500.0 c NaN dtype: floatés EX.NO: 4 PERFORMING MATHEMATICAL OPERATIONS ON SERIES OBJECTS AIM; To create a program in python to perform following mathematical Operations on Two Series objects: (i) Addition (ii) Subtraction (iii) Multiplication (iv) Division. SOURCE CODE: [import pandas as pd \S1=pd. Series ([10,20,30] ,index=[ \s2=pd. Series ([2,5],index=['a','b']) [print("The Addition of two series object is:") print (81+82) print ("The Subtraction of two series object i: print (S1-s2) print ("The Multiplication of two series object i print (s1*s2) print ("The Division of two series object is:") print (S1/s2) ",terd) RESULT: Thus, the above Python program is executed successfully and the output is verified. SAMPLE OUTPUT: The Addition of two series object is: 12.0 25.0 Nan 1: floates traction of two series object i: 8.0 15.0 Nan dtype: float6s ‘The Multiplication of two series object is: eo oueg a 20.0 b 100.0 © Nan dtype: floaté4 ‘The Division of two series object i a 5.0 b 4.0 c NaN dtype: float64 SHEED JOSS SOI SII SUIS III ASAIO ASOT DISPLAYING ATTRIBUTES OF SERIES AIM: To write a Python program to create a Series using list and display the following attributes of the Series: (i) index _{ii) dtype (iii) size (iv) shape (v) hasnans fu=[10,45,67,3,43] S=pd. Series (L,index=[ print print ("The data type of the Series is print ("The size of the Series is:",8.size) print ("The shape of the Series i: print ("The NaN of the Series is: RESULT: Thus, the above Python program is executed successfully and the output is verified. SAMPLE OUTPUT: The index of the Series is: Index({'a', e'], dtype='object') The data type of the Series is: inté4 The size of the Series is The shape of the Series is: (5,) ‘The NaN of the Series is: False EX.NO: 6 USING head{() and IN SERIES To write a Python program to create a Series using list of Marks of 10 students and display first 5 Students’ marks and Last 2 Students’ marks from Series object. [import pandas as pa 67 ,89,90, 86,100,45,83,43, 66,55] \Sepd. series Quarks, index=['stui', 'stu2’,'stu3’, /stud’, ‘stu’, "stu6’,'stu7’, ‘stua’, ‘Stuy’, "Stul0'] [print ("The First five student marks are:") [print (s.nead()) [prime (*\n") lprint ("me Last two students marks are:") [print (s.tai1(2)) RESUL: ‘Thus, the above Python program is executed successfully and the output is verified. SAMPLE OUTPUT: The First five student marks are: stul 67 stu2 89 stu3 90 stu4 86 stuS 100 dtype: int64 The Last two students marks are: stu9 66 stulo 55 dtype: inte4 CREATING DATAFRAME USING NESTED LIST To write a Python program to create a panda’s Data Frame for the following table Using Nested list: Name | Age stua__[Arun 2a stu2_|Bale 23, stu3__ [Charan 22] SOURCE CODE: Tmport pandas as pd CC 'Arun',21],['Bala’,23],{'Charan',22]] [D=pd.DataFrame (L,index=['Stul', 'Stu2','Stu3'],columns=['Name', 'Age']). [print (D) RESULT: Thus, the above Python program is executed successfully and the output is verified. SAMPLE OUTPUT: Name Age stul Arun 21 stu2 Bala 23 Stu3 Charan 22 EX.NO: 8 DATE: CREATING A DATAFRAME USING DICTIONARY OF LIST To write a Python program to create a panda’s DataFrame called DF for the following table Using Dictionary of List and perform the following operations: (i) To Display only column ‘Toys' from DataFrame DF. (ii) To Display the row details of ‘AP’ and 'OD' from DataFrame DF. (iii) To Display the column ‘Books’ and 'Uniform' for 'M.P' and 'U.P’ from DataFrame DF. (iv) To Display consecutive 3 rows and 3 columns from DataFrame DF. SOURCE CODE: 61571, 1610, 508,611,457), 110, 6798, 9611, 6457] ) [Dr=pd.DataFrame (D,index=['AP', '0D', 'M.P!, 'U.P'}) lprint ("the details of Toys are:") lprint (DF.1oeL:, ‘Toys! I) print ("\n") lprint ("The details of AP and oD are:") lprint (DF.tect ‘AP’: '0D',1) Iprint ("\n") [print ("The details of MP and U.P are:") lpeint (DF.toct'M.P':'U.P', ‘Books! : ‘Uniform’ ]) Ipeint ("\n") lprint (‘consecutive 3 Rows and 3 Columns are:') [print (pF.d10ct 1) RESULT: Thus, the above Python program is executed successfully and the output is verified. SAMPLE OUTPUT: The details of Toys are: AP 7916 oD 8508 M.P (7226 U.P 7617 Name: Toys, dtype: intéd The details of AP and OD are: Toys Books Uniform shoes AP 7916 61896 610 8810 op 8508 8208 508 6798 The details of MP and U.P are: Books Uniform M. 6149 611 U.P 6157 457 Consecutive 3 Rows and 3 Columns are: Toys Books Uniform AP 7916 61896 610 oD «8508 += 8208 508 M.P 7226 ©6149 611 DATE: ADDING A NEW COLUMN AND DELETING A ROW IN DATA FRAME To write a Python program to create a panda’s DataFrame called DF for the following table Using Dictionary of List and perform the following operations: tort | soos | Unitorm| show (i) Insert a new column “Bags” with values as [5891, 8628, 9785, 4475]. (ii) Delete the row details of M.P from DataFrame DF. SOURCE CODE: [import pandas as pd D={ 'Toys' :[7916,8508,7226,76171, "Books ' : (61896, 8208, 6149, 6157], ‘Uniform! : [610,508, 611,457], ‘Shoes! : (8810, 6798, 9611, 6457] } DF=pd.DataFrame(D,index=['AP’,'0D','M.P','U.P']) DFL'Bags']=[5891, 8628, 9785, 4475] # Adding a new column Bags print ("After Adding a new column [print (DF) print ("\n") \S=DF.drop('M.P') # Deleting M.P details. print ("After Deleting M.P details:") int (S) RESULT: Thus, the above Python program is executed successfully and the output is verified. SAMPLE OUTPUT: After Adding a new column: Toys Books Uniform Shoes Bags AP 7916 61896 610 8810 5891 oD 8508 8208 508 6798 8628 M.P 7226 6149 611 9611 9785 U.P 7617 6157 457 6457 4475 After Deleting M.P details: Toys Books Uniform Shoes Bags AP 7916 61896 610 8810 5891 oD 8508 8208 508 6798 8628 U.P 7617 6157 457 6457 4475 FRONT CE TICS III IR ROSETTA TIC OCCT TICE ACEI C IIIA ECAR OSIRIS II IS A Tel DATE: FILTERING DATA IN DATAFRAME ‘To write a Python program to create a panda’s DataFrame called DF for the following table using Dictionary of List and display the details of students whose Percentage is more than 85. ‘Stu_Name | Degree [Percentage st Anu | MBA 0 sz] Arun | mca 85 3 tan | Me * 7 76 MCA 3 SOURCE CODE: Et pandas as pd ={'Stu_Name':['Anu', 'Arun', 'Bala', 'Charan', 'Mano'], "Degree':['MBA', 'MCA','M.E','M.Sc', 'MCA'], ‘Percentage’ :[90,85,91,76,84]} F=pd.DataFrame (D,index=['S1','S2','S3','S4 rint (DF.loc[DF['Percentage']>85]) *s5'1) RESULT: Thus, the above Python program is executed successfully and the output is verified. SAMPLE OUTPUT: Stu_Name Degree Percentage sl Anu = MBA 90 83 Bala ME 91 Jan ZIR RIT ICIS SR ITO ISEIS ITE IIIS IIT IS II ITI III DISPLAYING ATTRIBUTES OF DATAFRAME To write a Python program to create a DataFrame using Dictionary and display the following attributes of the DataFrame: (i) index (ii) columns (iii) axes (iv) dtypes (v) shape (vi) dimension (vii) T SOURCE CODE: [import pandas as pd ID=(Stu Name':['Am ‘haran’,'Mano'], "Degree':[MBA’,’MCA’,’M.E',"M.Sc'], 'Percent'[90,85,91,76), |DF=p4.DataFrame(D,index=[‘Stu1','Stu2','Stu3','Stu4'}} lprint(’\nThe index of the DataFrame lprint("\nThe columns of the DataFrame lprint{"\nThe axes of the DataFrame |print{"\nThe data types of the DataFrame is: |print{"\nThe shape of the DataFrame is:",DF.shape) lprint{"\nThe Dimension of the DataFrame is:',DF.ndim) [print("\nThe transpose of the DataFrame is:\n",DF.T) RESULT: Thus, the above Python program is executed successfully and the output is verified. SAMPLE OUTPUT: “Tne commas of the Dutarrasse ie Tnden'stu Name’ ‘Degree, Percent, type“object) ‘The ance of the DataFrame i: [Undenq'tal', Sta, Sta, Stud], dtypevobjct),Inden('Stu Name’, Degree’, Percent], dtypes object “The data typen ofthe DataPrame le ‘Stu Mame "object Percent “intes ‘typet object ‘The shape ofthe DataFrame i: “3 ‘The Dimension of the DataPrame ie: SAMPLE OUTPUT: ‘The index of the DataFrame is: Index([Stul', ‘Stu’, 'Stu3’, 'Stu4], dtype='object') The columas of the DataFrame is: Index{['Stu_Name’, ‘Degree’, 'Percent|], dtype='object’) The axcs of the DataFramc is: [Index{'Sta1’, '‘Stu2', ‘Stu3', 'Stu4'], dtype='object'), Index(['Stu Name’, ‘Degree’, 'Percent'], dtype=‘object']] ‘The data types of the DataFrame is: Stu_Name object Degree object Percent int64 dtype: object ‘The shape of the DataFrame (4, 3) The Dimension of the DataFrame is: 2 The transpose of the DataFrame is: Stul Stu2 Stu3 Stu4 Stu Name Anu Bala Charan Mano Degree MBA MCA ME M.Sc Percent 90 &5 01 76 HAKKAR IKARIA KIRKE IRR KK REIKI IKARIA IKARIA KIKI IAAI AA RK EX.NO: 12 DATE: DISPLAYING DATA OF A DATFRAME ROW WISE AND COLUMN WISE USING iterrows() AND AIM: To write a Python program to create a panda’s DataFrame called Students for the following table and demonstrate iterrows and iteritems. 1 ‘Anu, "Arun" , "Bala", "Charan", "Mano"], "Degree": [°MBA" "NCA", "M.B","M.So", "MCA" ] | "Percentage": [90,85,91,76,84] } DF=pd.DataFrame (D,index=["S1","S2","$3","S4","S5"]) for (row,values) in DF.iterrows(): print (row) print(values) print()#To print an empty line after each row. for (ol, values) in DF.iteritems(): print (col) print (values) print () RESULT: Thus, the above Python program is executed successfully and the output is verified. SAMPLE OUTPUT: # Output for Iterrows(} si Stu_Name Anu Degree MBA Percentage 30 Name: $1, dtype: object 82 Stu Name Arun Degree MCA Percentage 85 Name: $2, dtype: object 83 Stu_Name Bala Degree ME Percentage a1 Name: $3, dtype: object 84 Stu_Name Charan Degree M.Se Percentage 76 Name: S4, dtype: object 35 stu_Name Mano Degree MCA Percentage a4 Name: 85, dtype: object # Output for Iteritems() Stu Name si Anu 82 Arun 83 Bala $4 Charan 85 Mano Name: Stu_Name, dtype: object Name: Degree, dtype: object Percentage s1 90 s2. 85 83 91 sa 76 s5 84 Name: Percentage, dtype: intéd EX.NO: 13 PLOTTING LINE CHART To write a Python program to plot a Line chart to depict the changing weekly Onion and Brinjal prices for four weeks. Also, give appropriate axes labels, title and keep marker style as Diamond and marker edge color as ‘red’ for Onion. SOURCE COD! import matplotlib.pyplot as pit Weeks=[1,2,3,4] \Onion=[45,25,32,80] 'Brinjal=[16,18, 45,50] pit. title ("Price Analysis") plt.xlabel ("weeks") [plt.ylabel ("Prices") plt.plot (Weeks ,Onion,marker='D' ,markersize=15 ,markeredgecolor=' r')| iplt.plot (Weeks , Brinjal) pit. show() RESULT: Thus, the above Python program is executed successfully and the output is verified. SAMPLE OUTPUT: Price Analysis Hes aS SSSI B ISB SII IIIS SSIS oS IIIS IIIA LISTS I EX.NO: 14 PLOTTING BAR CHART To write a Python program to plot a Bar chart for the following table and keep the width of each bar as 0.25 and specify each bar with different colors. Also, give proper title and axes labels for the bar chart. State | Players DL 5 TN iT AP 10 KA 7 SOURCE CODE: import matplotlib.pyplot as plt lstates=("Delhi", "TN", "AP", "KA"] Players=[5,11,10,7] pit.title("Bar Chart") [plt.xlabel ("states") plt.ylabel (‘Players’) plt.bar (States, Players ,width=0.25,color=['red','b','g', 'black']) plt. show() RESULT: Thus, the above Python program is executed successfully and the output is verified. SAMPLE OUTPUT: PLOTTING MULTIPLE BAR CHART To write a Python program to plot a Multiple Bar chart for the following table. Also, give Appropriate axes labels, title and legend. Country | Gold | Silver | Bronze AUS 80 59 59 IND 45 45 46 ENG 26 20 20 CAN 15 | 40 27 import matplotlib.pyplot as plt import numpy as np Info=["Gold", "Silver", "Bronze"] lCountry=["Aus", "Ind", "Eng", "Can"] |Aus=[80,59,591 Ind=[45,45, 46] Eng=[26, 20,20] can=[15, 40,27] Xenp. arange (3) \plt .bar (Info, Aus,width=.15,label='Aus ') plt.bar (X+0.15,Ind,width=,15,label='Ind') plt .bar (X+0.30,Eng,width=,15,label= iplt.bar (X+0.45,Can,width=.15,label=" Thus, the above Python program is executed successfully and the output is verified. SAMPLE OUTPUT: gaae oid gg2k 8 YUTPUT: ° " 60 sO “ 20 » ° Gold KKK KEKEKKEKEK KKK KK RK ERK KKK ERK RRR KKK RRR RRR ERR RRR KER KE RRK KKK ERR EERE Wh Silver To write a Python program to plot a Histogram for the following class interval or range. Also, give appropriate axes name, title and edege color as ‘red’. [import matplotlib.pyplot as plt ‘ks=[40 , 60,55, 20, 35,70,60,89, 20,33] 1t.title("Maths Marks-Histogram of class XII") 1t.xlabel ("Mark Ranges") 1t.ylabel ("No.of Students") 1t. hist (Marks ,bins=[0, 33,45, 60,100] ,edgecolor='red' 11t. show() RESULT: Thus, the above Python program is executed successfully and the output is verified. SAMPLE OUTPUT: Math Maks toprol To Write a Python program to store the details of Employess’ such as Empno, Name, Salary into a Employee.csv file. Also, write a code to read employee details from csv file. SOURCE CODE: import pandas as pd Emps{ "Name": ["Anu", "Ram", "Raj", "Mano" "age": (25,27,35,27,321, "state": ["TN", "AB", "TN", "KA", "AB"], "Sa lary" : [26000, 35000, 45000, 2500037000] ) DF=pd.DataFrame (Emp, index=["E1","E2","£3","E4","E5"]) DF.to_csv("E:\\Data\\Emp.csv") Data=pd.read_csv("E:\\Data\\Emp.csv") print (Data) Rajan"), RESULT: Thus, the above Python program is executed successfully and the output is verified. SAMPLE OUTPUT: El Anu 25 TN 26000 E2 Ram 27 AP 35000 E3 Raj 35 «TN 45000 EA Mano 27 KA 25000 E5 Rajan 32 AP 37000 were Ex.No: 1 DATE: SQL COMMANDS EXERCISE - 1 To write Queries for the following Questions based on the given table: EmpID| Name |Gender| Age Dept DOs Salary City 1_| Praveen | M 25 Sales 1989-06-08 20000 | Chennai 2 [Arun [M 29 Marketing | 1989-09-26 22000 | Chennai 3 [Usha | F 27 Finance | 1994-08-09 25000 | Bangalore 4 [Bala | M 31 Sales 1990-03-23 27000 | NULL. 5 Rani__|F 28 Marketing | 1990-04-23 27000 | Mumbai 6 Nisha__| F 26 NULL 1991-02-24 18000 __| Bangalore 7 | Manoj__| M 32 Finance | 1982-05-06 30000 | Goa {a) Write a Query to Create a new database in the name of "EMPS" Sol: CREATE DATABASE EMPS; {b) Write a Query to Open the database EMPS Sol: USE EMPS; (ce) Write a Query to create the above table called: Info Sol: CREATE TABLE INFO (EmpID int primary key, Name varchar(15),Gend varchar(3),Age int,Dept varchar(15),DOJ date, Salary int, City varchar(10}); (4) Write a Query to list all the existing database names. Sol: mysql > SHOW DATABASES; {e) Write a Query to List all the tables that exists in the current database. Sol mysql> SHOW TABLES; {f) Write a Query to insert all the rows of above table into Info table. INSERT INTO INFO VALUES (1,'Praveen',’M', 25,'Sales’,'1989-06-08','20000','Chennai’); INSERT INTO INFO VALUES(2, Arun’,'M',29,'Marketing’,'1989-09-26',22000, Chennai); INSERT INTO INFO VALUES(3,'Usha’, ,27,'Finance','1994-08-09',25000,'Bangalore’); INSERT INTO INFO VALUES(4,'Bala’,'M’, 1,'Sales',’1990-03-23',27000,NULL); INSERT INTO INFO VALUES(5,'Rani ,28,/Marketing’,'1990-04-23',27000,'Mumbai'); INSERT INTO INFO VALUES ( Nisha’,‘F, 26, NULL,'1991-02-24', 18000, Bangalore); INSERT INTO INFO VALUES (7,'Manoj ,’M’, 32,'Finance','1982-05-06', 30000, Goa’); {g) Write a Query to display all the details of the Employees from the above table INFO’. Sol: mysql> SELECT * FROM INFO; Ex.No: 2 DATE: SQL COMMANDS EXERCISE - 2 AIM: To write Queries for the following Questions based on the given table: EmpID | Name |Gender| Age Dept Dos Salary City 1 | Praveen! _M 25 | Sales 1989-06-08 | 20000_| Chennai 2 | Arun M 29 | Marketing | 1989-09-26 | 22000 | Chennai 3 | Usha F 27 | Finance 1994-08-09 | 25000 | Bangalore 4 | Bala M 31__| Sales 1990-03-23 | 27000 NULL S| Rani F 28 | Marketing | 1990-04-23 | 27000 | Mumbai 6 | Nisha F 26 | NULL 1991-02-24| 18000 | Bangalore [77 Manoj | 32 | Finance 1982-05-06 | 30000 Goa {a) Write a Query to Display Employees’ name and City from the above table. {b) Write a Query to Display all details of Employees who are living in Chennai. Sol mysql> SELECT * FROM INFO WHERE CITY='CHENNAT'; (c) Write a Query to get the name and salary of the employee whose salary is above 15000 and gender is not male. Sol: mysql> SELECT NAME,SALARY FROM INFO WHERE SALARY >15000 AND GENDER©'M’; Output: (4) Write a query to update increase 10% Salary of an employee whose City is ‘CHENNAT and Gender is ‘MALE’. UPDATE INFO SET SALARY=SALARY+ (SALARY*0.10) WHERE CITY='CHENNAI' AND GENDER=' 5 Output (After Updating): (e) Write a Query to delete the details of Employee Id 6. Se mysql > DELETE FROM INFO WHERE EMPID: Output (After Deletio: Ex.No: 3 DATE: SQL COMMANDS EXERCISE - 3 AIM: To write Queries for the following Questions based on the given table: EmpID | Name | Gender | Age Dept DOs Salary City 1 | Praveen] M | 25 | Sales 1989-06-08 | 20000 | Chennai 2 ‘Arun M_ | 29 | Marketing | 1989-09-26 | 22000 | Chennai 3 | Usha F 27 | Finance 1994-08-09 | 25000 | Bangalore 4 | Bala M_ | 31 __| Sales 1990-03-23 | 27000 NULL. 5 | Rani F | 28 | Marketing | 1990-04-23 27000 | Mumbai 7 | Manoj | M_| 32 _| Finance 1982-05-06 | 30000 Goa {a) Write a Query to list names of Employees in Descending order. Sol: mysql> SELECT NAME FROM INFO ORDER BY NAME; Output: (b) Write a Query to find a total salary of all employees. Sol: mysql> SELECT SUM(SALARY) FROM INFO; Output: (c) Write a Query to display maximum salary and minimum salary of employees. Sol: mysql> SELECT MAX(SALARY),MIN(SALARY) FROM INFO; {d) Write a Query to count the number of employees earning more than 25000. mysql> SELECT COUNT(SALARY) FROM INFO WHERE SALARY>25000; Output: {e) Write a query to display sum of salary of the employees grouped by department wise. Sol: mysql> SELECT DEPT,SUM(SALARY) FROM INFO GROUP BY DEPT; (9 Write a query to display the department names where number of employees are greater than or equal to 2. DATE: SQL COMMANDS EXERCISE - 4 To write Queries for the following Questions based on the given table: {a) Write a Query to display Remainder of column Marks divide by 3 Sol: mysql> SELECT MOD(MARKS,3) FROM STU; Output: (b) Write a Query to display department name and its respective number of characters in Dept column. Sol: mysql> SELECT DEPT,LENGTH(DEPT) FROM STU; {c) Write a Query to display first 2 characters of the column Name. mysql> SELECT LEFT(NAME,2) FROM STU; Output: {d) Write a Query to display first 2 characters of the column Name. Sol mysql> SELECT RIGHT(NAME,2) FROM STU; Output: {e) Write a Query to display name of all the students from 3« character to 5% character in the field Name of the STU table. Sol: mysql> SELECT SUBSTR(NAME,3,5) FROM STU; () Write a Query to display student name and month of date of admission of all students. mysql> SELECT NAME,MONTH(DOA) FROM STU; Output: (g) Write a Query to display Student name and day name of the students’ DOA of the table (h) Write a Query to display Student name and month name of the students’ DOA of the table STU. Sol: mysql> SELECT NAME,MONTHNAME(DOA)FROM STU; Output:

You might also like