IP Record Python 23-24 Aryan
IP Record Python 23-24 Aryan
PROGRAMS
Data Handling Using
Pandas
Informatics Practices Practical Record 2023-24
Program 1
SOURCE CODE:
import pandas as pd
import numpy as np
items={'phone':15,'laptop':15,'tablet':10}
S1=pd.Series(items)
print(S1)
ar=np.array([2,4,6,8])
S2=pd.Series(ar)
print(S2)
OUTPUT:
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
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
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:
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)
OUTPUT:
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:
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)
OUTPUT:
Program 8
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']))
OUTPUT:
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(df.subtract(mean,axis=0))
OUTPUT:
Program 10
(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', ])
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:
Program 11
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
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:
Program 13
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:
PYTHON
PROGRAMS
Department of Computer Science, CEHS Dubai
P a g e | 26
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:
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:
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.show()
OUTPUT:
Program 16
Aim: For the Data frames created above, analyze and plot multiple bar graphs with
title and legend.
SOURCE CODE:
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
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:
MySQL
PROGRAMMS:
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.
PROGRAM 2.1:
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:
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:
Aim: To write a sql query to order the (student ID, marks) tables in
decreasing order of the marks.
PROGRAM 3:
Aim: Create the following table EMP, insert same values and execute the
following queries
Table: EMP
6. To display Name of all employees from 2nd character to 4th character in the filed
Name
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
11.To display the name of the Employee whose names start with the letter ‘S’
NETWORKING
&
TOPOLOGIES: