Programs For Practical
Programs For Practical
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 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.
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
NOTE:
Board Practical Question Paper will contain One Python question and one
Mysql Table.