0% found this document useful (0 votes)
6 views

Programs For Practical

Introduction

Uploaded by

ansar fahi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Programs For Practical

Introduction

Uploaded by

ansar fahi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

M.E.

S INDIAN SCHOOL, DOHA -QATAR


2024- 2025
PRACTICAL LIST- DATA HANDLING AND MYSQL

1. Write a python program to plot a line chart based on the given data to depict the changing weekly
average temperature in Delhi for four weeks. Give suitable labels and title.
Week=[1,2,3,4]
Avg_week_temp=[ 40,42,38,44]
import matplotlib.pyplot as plt
Week=[1,2,3,4]
Avg_week_temp=[40,42,38,44]
plt.plot(Week, Avg_week_temp)
plt.xlabel(“week”)
plt.ylabel(“Temperature”)
plt.title(“Average temperature of Delhi in four weeks”)
plt.show()

2. Write a program to plot a bar graph showing the stream wise number of admissions in an engineering college.
Differentiate the streams with different colors.

import matplotlib.pyplot as plt


streams= ['Civil', 'Electrical', 'Mechanical',
'Chemical','CS']
numofadm = [15, 35, 40, 20, 50]
plt.bar(streams,numofadm,,color=[“r”,”c”,”m”,”g”,”b”])
plt.xlabel(“Streams”)
plt.ylabel(“Number of admissions”)
plt.title("Stream Wise number of admissions")
plt.show()

3. Write a Pandas program to perform arithmetic operations on two Pandas Series.


import pandas as pd
ds1 = pd.Series([3, 6, 9, 12, 15],index=["a","b","x","y","z"])
ds2 = pd.Series([2, 4, 6,8],index=["a","b","y","z"])ds
= ds1 + ds2
print("Add two Series:")
print(ds)
print("Subtract two Series:")ds
= ds1 - ds2
print(ds)
print("Multiply two Series:")ds
= ds1 * ds2
print(ds)
print("Divide two Series:")ds
= ds1 / ds2
print(ds)
4.Write a python code to create a dataframe ‘result’ and for the questions as per given below table.
PT1 PT2 PT3
CLASS7 84.5 78.6 81.4
CLASS8 76.4 82.4 81.7
CLASS9 89.6 89.2 87.2
CLASS10 95.4 94.3 97.5

a) Display the number of elements in the dataframe.


b) Display the number of rows and columns.
c) Display the dimension of the dataframe.
d) Display the datatypes of the columns.
e) Display the row labels.
f) Display the column labels.

import pandas as pd
d={" PT1": [84.5,78.4,89.6,95.4],"PT2": [78.6, 82.4,89.2,94.3], "PT3":81.4,81.7,88.2,97.5]}
result=pd.DataFrame(d,index=["CLASS7","CLASS8","CLASS9","CLASS10"])
print(result)
print(result.size)
print(result.shape)
print(result.ndim)
print(result.dtypes)
print(result.index)
print(result.columns)

5. Naman has created the following dataframe “Climate” to record the data about climatic conditions offour
years.

1.Add a record of climatic conditions for the year 2021.2.Display


the first three records.
3.Change the details for the year 2020 as 36,25,165.
4.Display the 3rd record from the dataframe.
5.Display the last 2 records.

import pandas as pd
data=[{'Year':2017,'MaxTemp':32,'MinTemp':20,'Rainfall':123},{'Year':2018,'MaxTemp':33,'MinTemp':22,
'Rainfall':140},{'Year':2019,'MaxTemp':35,'MinTemp':21,'Rainfall':35},{'Year':2020,'MaxTemp':34,'MinTe
mp':23,'Rainfall':160}]
climate=pd.DataFrame(data)
print(climate)
climate.loc[4]=[2021,30,35,150] #1
print(climate.head(3)) #2
climate.iloc[3]=[2020,36,25,165] #3
print(climate.iloc[2]) #4
print(climate.tail(2)) #5

6. Zeenat has created the following data frame dataframe1 to keep track of data Rollno, Name, Marks1
and Marks2 for various students of her class where row indexes are taken as the default values:
1) Retrieve first 3 columns
2) Add one more column Marks3 with values (70,60,65,80)
3)Modify column Marks 2 as (60,50,50,40)
4)Add another column Total by adding all the three marks.
5)Remove the column Total from the above dataframe
6)Change the column index of Marks1,Marks2 as M1,M2 .

import pandas as pd
dataframe1=pd.DataFrame({"Rollno":pd.Series([1,2,3,4]),
"Name":pd.Series(["Swapnil Sharma","RajBatra","Bhoomi Singh","Jay Gupta"]),
"Marks1":pd.Series([30,75,82,90]),
"Marks2":pd.Series([50,45,95,95])})
print(dataframe1.iloc[:,0:3]) #1

dataframe1["Marks3"]=[70,60,65,80]
print(dataframe1) #2

dataframe1["Marks2"]=[60,50,50,40]
print(dataframe1) #3

dataframe1["Total"]=dataframe1["Marks1"]+dataframe1["Marks2"]+dataframe1["Marks3"]
print(dataframe1) #4

dataframe1.drop(columns="Total",inplace=True)
print(dataframe1) #5

dataframe1.rename(columns={"Marks1":"M1","Marks2":"M2"},inplace=True)
print(dataframe1) #6

7. MYSQL TABLE: PRODUCT

8. MYSQL TABLE: SALESMAN

9. MYSQL TABLE :TEACHER

NOTE:

Board Practical Question Paper will contain One Python question and one
Mysql Table.

You might also like