0% found this document useful (0 votes)
23 views42 pages

IP Record Python 23-24 Aryan

Uploaded by

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

IP Record Python 23-24 Aryan

Uploaded by

cehsp7725
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 42

PYTHON

PROGRAMS
Data Handling Using
Pandas
Informatics Practices Practical Record 2023-24

Program 1

Aim: To Create a pandas series from a dictionary of values and an ndarray

SOURCE CODE:
import pandas as pd

import numpy as np

items={'phone':15,'laptop':15,'tablet':10}

S1=pd.Series(items)

print("Series object is:")

print(S1)

ar=np.array([2,4,6,8])

S2=pd.Series(ar)

print("Series object 2 is:")

print(S2)

OUTPUT:

Department of Computer Science, CEHS Dubai


Page |6
Informatics Practices Practical Record 2023-24

Program 2

Aim: Being given a series, to print all the elements that are above the 75 th percentile.

SOURCE CODE:

import pandas as pd
import numpy as np
ar=np.array([34,13,72,86,76,98])
S1=pd.Series(ar)
quantilevalue=S1.quantile(q=0.75)
print("75th quantile value is :",quantilevalue)
print("values that are greater than 75th quantile value")
for val in S1:
if(val>quantilevalue):
print(val, end=" ")
OUTPUT:

Program 3

Department of Computer Science, CEHS Dubai


Page |7
Informatics Practices Practical Record 2023-24

Aim: To 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
total expenditure per category.

SOURCE CODE:
import pandas as pd

data={"category":['phone','laptop','tablet'],"Item":
['apple','samsung','apple'],"amount":[1500,3000,1000]}

Sales_quaterly = pd.DataFrame(data)

print(Sales_quaterly)

df=Sales_quaterly.groupby("Item")
total=df["amount"].sum()
print(total)
pivoted_df=Sales_quaterly.pivot_table(index="Item",values="amoun
t",aggfunc="sum")
print(pivoted_df)

OUTPUT:

Program 4

Department of Computer Science, CEHS Dubai


Page |8
Informatics Practices Practical Record 2023-24

Aim: To create a data frame based on ecommerce data and generate descriptive
statistics (mean, median, mode, quartile, and variance)

SOURCE CODE:
import pandas as pd

data={'Item':
['phone','laptop','tablet','computer'],'price':
[1500,4000,2000,8000],'Quantity':[2,3,1,3]}

df=pd.DataFrame(data)

print(df)

print(df.mean())

print(df.median())

print(df.mode())

print(df.quantile([0.25,0.50,0.75]))

print(df.var())

OUTPUT:

Department of Computer Science, CEHS Dubai


Page |9
Informatics Practices Practical Record 2023-24

Program 5

Aim: To Create a data frame for examination result and display row labels, column
labels data types of each column and the dimensions

SOURCE CODE:

import pandas as pd
data={'Eng':[90,87,94,96,91],'IP':[92,82,90,87,86],'Acc':
[78,84,86,91,79],'Eco':[94,92,83,85,87],'Business':
[86,88,97,95,93],'marks':[346,433,450,454,436]}
df=pd.DataFrame(data,index=["Amit","sohan","mohan","neha",
"sachin"])
print(df)
print(df.index)
print(df.columns)
print(df.dtypes)
print(df.ndim)
print(df.size)
print(df.shape)
print(df.T)

Department of Computer Science, CEHS Dubai


P a g e | 10
Informatics Practices Practical Record 2023-24

OUTPUT:

Department of Computer Science, CEHS Dubai


P a g e | 11
Informatics Practices Practical Record 2023-24

Program 6

Aim: To filter out rows based on different criteria such as duplicate rows.

SOURCE CODE:

import pandas as pd
data={"Item":
['phone','laptop','computer','tablet'],"price":
[1500,4000,8000,2000],'location':
['jaipur','kolkata','delhi','mumbai']}
df=pd.DataFrame(data)
print(df)
print("all the duplicate rows :")
print(df[df.duplicated()])
print("duplicate rows on the basis of Item column :")
print(df[df.duplicated(['Item'])])
OUTPUT:

Department of Computer Science, CEHS Dubai


P a g e | 12
Informatics Practices Practical Record 2023-24

Program 7

Aim: To find the sum of each column, or find the column with the lowest mean

SOURCE CODE:

import pandas as pd
data_dict={'A':[10,20,30,40],'B':[5,10,15,30],'C':
[15,25,35,45],'D':[20,40,60,80]}
df=pd.DataFrame(data_dict)
print("column wise sum is:")
print(df.sum())
print("Column wise mean is:")
print(df.mean())
ser=df.mean()
sorted_ser=ser.sort_values(ascending=True)

Department of Computer Science, CEHS Dubai


P a g e | 13
Informatics Practices Practical Record 2023-24

print("lowest mean column name and its value is:")


print(sorted_ser[0:1])

OUTPUT:

Department of Computer Science, CEHS Dubai


P a g e | 14
Informatics Practices Practical Record 2023-24

Program 8

Aim: To locate the 3 largest values in a data frame.

SOURCE CODE:
import pandas as pd

data={'A':[7,4,9,18],'B':[56,82,74,90],'C':
[93,40,77,67],'D':[98,56,34,71]}

df = pd.DataFrame(data)

print(df)

print(df.nlargest(3,['A']))

print(df.nlargest(3,['B']))

print(df.nlargest(3,['C']))

print(df.nlargest(3,['D']))

Department of Computer Science, CEHS Dubai


P a g e | 15
Informatics Practices Practical Record 2023-24

OUTPUT:

Department of Computer Science, CEHS Dubai


P a g e | 16
Informatics Practices Practical Record 2023-24

Program 9

Aim: To subtract the mean of a row from each element of the row in Data Frame.

SOURCE CODE:
import pandas as pd

data={'A':[10,20,30,40],'B':[50,60,70,80],'C':
[90,100,110,120],'D':[130,140,150,160]}

df=pd.DataFrame(data)

print(df)

mean=df.mean(axis=1)

print(mean)

print('DataFrame after subtracting row mean from each


element of row:')

print(df.subtract(mean,axis=0))

Department of Computer Science, CEHS Dubai


P a g e | 17
Informatics Practices Practical Record 2023-24

OUTPUT:

Program 10

Department of Computer Science, CEHS Dubai


P a g e | 18
Informatics Practices Practical Record 2023-24

Aim: 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.

(v) Insert a new column “Bags” with values as [5891, 8628, 9785, 4475].
(vi) Delete the row details of M.P from DataFrame DF.

SOURCE CODE:
import pandas as pd
D={'Toys':[7916, 8508, 7226, 7617],'Books':
[61896,8208,6149,6157],'Uniform':
[610,508,611,4571],'Shoes':[8810,6798,9611,6457]}
DF=pd.DataFrame (D,index= ['AP','OD','M.P','U.P'])
print(DF)
print ("The details of Toys are:")
print (DF.loc[:,'Toys'])
print ("\n" )
print ("'The details of AB and OD are:")
print (DF.loc ['AP':'OD', ])

Department of Computer Science, CEHS Dubai


P a g e | 19
Informatics Practices Practical Record 2023-24

print ("\n")
print ("The details of MP and UP are:")
print(DF.loc['AP':'U.P','Books':'Uniform'])
print ("\n")
print('consecutive 3 rows and 3 columns are:')
print (DF.iloc[0:3,0:3])
DF['bags']=[5891,8628,9785,4475]
print('after adding a new column:')
print(DF)
print ("\n")
s=DF.drop('M.P')
print('after deleting M.P details:')
print(s)

OUTPUT:

Department of Computer Science, CEHS Dubai


P a g e | 20
Informatics Practices Practical Record 2023-24

Program 11

Department of Computer Science, CEHS Dubai


P a g e | 21
Informatics Practices Practical Record 2023-24

Aim: 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.

SOURCE CODE:

import pandas as pd

d={'stu_name':['anu','arun','bala','charan','mano'],'degree':
['MBA','MCA','M.E','M.Sc','MCA'],'percentage':[90,85,91,76,84]}

df=pd.DataFrame(d,index=['S1','S2','S3','S4','S5'])

print(df)

print(df.loc[df['percentage']>85])

OUTPUT:

Program 12

Department of Computer Science, CEHS Dubai


P a g e | 22
Informatics Practices Practical Record 2023-24

Aim: To create a panda’s DataFrame called Students for the following


table and demonstrate iterrows and iteritems

SOURCE CODE:
import pandas as pd
d={'stu_name':
['anu','arun','bala','charan','mano'],'degree':
['MBA','MCA','M.E','M.Sc','MCA'],'percentage':
[90,85,91,76,84]}
df=pd.DataFrame(d,index=['S1','S2','S3','S4','S5'])
for (rows,values) in df.interrows():
print(rows)
print(values)
print()

OUTPUT:

Department of Computer Science, CEHS Dubai


P a g e | 23
Informatics Practices Practical Record 2023-24

Department of Computer Science, CEHS Dubai


P a g e | 24
Informatics Practices Practical Record 2023-24

Program 13

Aim: To store the details of Employee such as EMPNO, Name, Salary to


CSV file (epm.csv). To read Employee details from CSV file

SOURCE CODE:

import pandas as pd
emp={'name':['anu','ram','raj','mano','rajan'],'age':
[25,27,35,27,32],'state':
['TN','AP','TN','KA','AP'],'salary':
[26000,35000,45000,25000,37000]}
df=pd.DataFrame(emp,index=['E1','E2','E3','E4','E5'])
df.to_csv('C:\\Users\\Crescent lab\\Desktop\\emp.csv')
print('all values inserted')
data=pd.read_csv('C:\\Users\\Crescent lab\\Desktop\\
emp.csv')
print(data)
OUTPUT:

Department of Computer Science, CEHS Dubai


P a g e | 25
Informatics Practices Practical Record 2023-24

PYTHON
PROGRAMS
Department of Computer Science, CEHS Dubai
P a g e | 26
Informatics Practices Practical Record 2023-24

Data Visualization Using


Matplotlib

Department of Computer Science, CEHS Dubai


P a g e | 27
Informatics Practices Practical Record 2023-24

Program 14

Aim: 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 CODE:
import matplotlib.pyplot as plt
Weeks=[1,2,3,4]
Onion=[20,40,45,80]
Brinjal=[10,18,45,50]
plt. title ("Price variations")
plt. xlabel ("Weeks")
plt. ylabel ("Prices")
plt. plot (Weeks,Onion,marker='D',markersize=15,
markeredgecolor='r')
plt. plot (Weeks, Brinjal)
plt. show ()

OUTPUT:

Department of Computer Science, CEHS Dubai


P a g e | 28
Informatics Practices Practical Record 2023-24

Program 15

Aim: To plot a bar graph to given the school result data, analyze the performance of
the students on different parameters, e.gsubject wise or class wise.

SOURCE CODE:

import matplotlib.pyplot as plt

subject=['ECO','BS','ACC','ENG',’IP’]

percentage=[85,78,65,98,24]

plt.bar(subject,percentage,align='center',color='green')

plt.xlabel('subject name')

plt.ylabel('pass percentage')

plt.title('bar graph for result analysis')

plt.show()

OUTPUT:

Department of Computer Science, CEHS Dubai


P a g e | 29
Informatics Practices Practical Record 2023-24

Program 16

Aim: For the Data frames created above, analyze and plot multiple bar graphs with
title and legend.

SOURCE CODE:

import matplotlib.pyplot as plt


import numpy as np
s=['1st','2nd','3rd']
per_Sc=[95,89,98]
per_Com=[88,93,90]
per_hum=[77,75,77]
x=np.arange(len(s))
plt.bar(x,per_Sc,label='science',width=0.25,color='green')

Department of Computer Science, CEHS Dubai


P a g e | 30
Informatics Practices Practical Record 2023-24

plt.bar(x+.25,per_Com,label='commerce',width=0.25,color='r
ed')
plt.bar(x+.50,per_hum,label='humanities',width=0.25,color=
'gold')
plt.xticks(x,s)
plt.xlabel('position')
plt.ylabel('percentage')
plt.title('bar graph for result analysis')
plt.legend()
plt.show()
OUTPUT:

Program 17

Aim: To Plot a Histogram for the following class interval or range.

Department of Computer Science, CEHS Dubai


P a g e | 31
Informatics Practices Practical Record 2023-24

SOURCE CODE:

import matplotlib.pyplot as pt
marks=[45,50,40,35,60,56,45,43,43]
pt.title("Class 12 Accountancy marks")
pt.xlabel("mark range")
pt.ylabel("students")
pt.hist(marks,color='black',bins=[1,20,50,60,
99],edgecolor='blue')
pt.show()

OUTPUT:

Department of Computer Science, CEHS Dubai


P a g e | 32
Informatics Practices Practical Record 2023-24

MySQL
PROGRAMMS:

Department of Computer Science, CEHS Dubai


P a g e | 33
Informatics Practices Practical Record 2023-24

PROGRAM 1:
Objective: Understanding the use of DDL & DML command.
Aim: Open MySQL. Write and Execute the SQL command for the following
1)Create and open Database named MYORG.

2)Write commands to display the system date.

3)Write a command to display the name of current month.

Department of Computer Science, CEHS Dubai


P a g e | 34
Informatics Practices Practical Record 2023-24

4)Write the command to round off value 15.193

5)Write a query to find out the result of 63.

PROGRAM 2.1:

Department of Computer Science, CEHS Dubai


P a g e | 35
Informatics Practices Practical Record 2023-24

Aim: To create a student table with the student id, name and marks as
attributes where the student id is the primary key.

PROGRAM 2.2:
Aim: To insert details of 6 new students in the above table.

PROGRAM 2.3:
Aim: To display details of a new student table.

PROGRAM 2.4:

Department of Computer Science, CEHS Dubai


P a g e | 36
Informatics Practices Practical Record 2023-24

Aim: To delete the details of a particular student in the above table.

PROGRAM 2.5:
Aim: To use the select command to get details of the students with marks
more than 80.

PROGRAM 2.6:
Aim: To find the min, max, sum and average of the marks in a student’s
table.

PROGRAM 2.7:

Department of Computer Science, CEHS Dubai


P a g e | 37
Informatics Practices Practical Record 2023-24

Aim: To write a sql query to order the (student ID, marks) tables in
decreasing order of the marks.

Department of Computer Science, CEHS Dubai


P a g e | 38
Informatics Practices Practical Record 2023-24

PROGRAM 3:
Aim: Create the following table EMP, insert same values and execute the
following queries

Table: EMP

EmpID Name Designation Doj Salary Com


8369 SMITH CLERK 1989-06-08 800.756 NULL

8499 ANYA SALESMAN 1989-09-26 1600.456 300

8521 SETHU SALESMAN 1250.125 500


1994-08-09
8566 MANU MANAGER 1990-03-23 2985.495 NULL

8467 PREETI HR 1990-04-23 2850.999 200

8756 SUMIT MANAGER 1991-02-24 2500.248 100

Department of Computer Science, CEHS Dubai


P a g e | 39
Informatics Practices Practical Record 2023-24

1. To display Name and number of characters of an employees whose salary are


greater than or equal to 1500

2. To display details of employs who are not getting commission

3. To display Remainder of Column Salary divided by 3

4. To display Name and Number of characters in Name column

Department of Computer Science, CEHS Dubai


P a g e | 40
Informatics Practices Practical Record 2023-24

5. To display first 5 characters of the designation column

6. To display Name of all employees from 2nd character to 4th character in the filed
Name

Department of Computer Science, CEHS Dubai


P a g e | 41
Informatics Practices Practical Record 2023-24

7. To display Name and Month of Joining date of all employees

8. To display Name and Day Name of Joining date of all employees

Department of Computer Science, CEHS Dubai


P a g e | 42
Informatics Practices Practical Record 2023-24

9. To display the name of the employee who are working as salesman in the
descending order of their salary

10.To display Name and round off Salary with 2 decimal places of the employee

Department of Computer Science, CEHS Dubai


P a g e | 43
Informatics Practices Practical Record 2023-24

11.To display the name of the Employee whose names start with the letter ‘S’

12.To display the number of Employee in each designation

Department of Computer Science, CEHS Dubai


P a g e | 44
Informatics Practices Practical Record 2023-24

NETWORKING
&
TOPOLOGIES:

Objective: To check the IP configuration and topology of the system in


Computer lab

Department of Computer Science, CEHS Dubai


P a g e | 45
Informatics Practices Practical Record 2023-24

Topology: Star Topology

Department of Computer Science, CEHS Dubai


P a g e | 46

You might also like