Q. Series objects Temp1, Temp2, Temp3, Temp4 store the temperatures of days of week1, week2, week3, weeken4 respectively. Write a script to
(a) Print the average temperature per week
(b) Print average temperature of entire month.
You can understand by Watching video :-
Answer =
#(a) import pandas as pd avg_tem = [28.4,30.55,25,35,37,39,28,\ 28,30.8,25.0,35,35.4,29,27.1,\ 24,30,21,31,37,39,32.5,\ 28,30,28.8,35,37,39,28,\ 28,30,25] Temp1 = pd.Series(avg_tem[:7]) Temp2 = pd.Series(avg_tem[8:15]) Temp3 = pd.Series(avg_tem[16:23]) Temp4 = pd.Series(avg_tem[23:30]) print('Average temp of week1 \n', Temp1.sum()/7) print('Average temp of week2 \n', Temp2.sum()/7) print('Average temp of week3 \n', Temp3.sum()/7) print('Average temp of week4 \n', Temp4.sum()/7) #(b) import pandas as pd avg_tem = [28.4,30.55,25,35,37,39,28,\ 28,30.8,25.0,35,35.4,29,27.1,\ 24,30,21,31,37,39,32.5,\ 28,30,28.8,35,37,39,28,\ 28,30,25] Temp1 = pd.Series(avg_tem[:7]) Temp2 = pd.Series(avg_tem[8:15]) Temp3 = pd.Series(avg_tem[16:23]) Temp4 = pd.Series(avg_tem[23:30]) sum = Temp1.sum() + Temp2.sum() + Temp3.sum() + Temp4.sum() print('Average temp of entire month \n', sum/len(avg_tem))
Output :-
(a)
Average temp of week1
31.849999999999998
Average temp of week2
29.471428571428568
Average temp of week3
31.214285714285715
Average temp of week4
32.25714285714286
(b)
Average temp of entire month
28.179032258064513
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )