Informatics Practices
Series objects Temp1, Temp2, Temp3, Temp4 store the temperatures of days of week1, week2, week3, week4 respectively.
Write a script to
(a) print the average temperature per week.
(b) print average temperature of entire month.
Python Pandas
3 Likes
Answer
import pandas as pd
Temp1 = pd.Series([28.0, 30.2, 26.1, 29.6, 27.7, 31.8, 25.9])
Temp2 = pd.Series([25.5, 24.5, 23.6, 22.7, 21.8, 20.3, 19.2])
Temp3 = pd.Series([32.4, 33.3, 34.1, 33.2, 32.4, 31.6, 30.9])
Temp4 = pd.Series([27.3, 28.1, 29.8, 30.6, 31.7, 32.8, 33.0])
Week_1 = sum(Temp1)
Week_2 = sum(Temp2)
Week_3 = sum(Temp3)
Week_4 = sum(Temp4)
print("Week 1 : Average Temperature is", Week_1 / 7, "degree Celsius")
print("Week 2 : Average Temperature is", Week_2 / 7, "degree Celsius")
print("Week 3 : Average Temperature is", Week_3 / 7, "degree Celsius")
print("Week 4 : Average Temperature is", Week_4 / 7, "degree Celsius")
total = Week_1 + Week_2 + Week_3 + Week_4
print("\nAverage temperature of entire month:", total / 28, "degree Celsius")Output
Week 1 : Average Temperature is 28.47142857142857 degree Celsius
Week 2 : Average Temperature is 22.514285714285712 degree Celsius
Week 3 : Average Temperature is 32.55714285714286 degree Celsius
Week 4 : Average Temperature is 30.47142857142857 degree Celsius
Average temperature of entire month: 28.503571428571426 degree Celsius
Answered By
2 Likes
Related Questions
Write Python code to create a Series object Temp2 storing temperatures of seven days of week. Its indexes should be 'Sunday', 'Monday',… 'Saturday'.
A series object (say T1) stores the average temperature recorded on each day of a month. Write code to display the temperatures recorded on :
(i) first 7 days
(ii) last 7 days.
Ekam, a Data Analyst with a multinational brand has designed the DataFrame df that contains the four quarters' sales data of different stores as shown below :
Store Qtr1 Qtr2 Qtr3 Qtr4 0 Store1 300 240 450 230 1 Store2 350 340 403 210 2 Store3 250 180 145 160 Answer the following questions :
(i) Predict the output of the following Python statement :
(a) print(df.size) (b) print(df[1:3])(ii) Delete the last row from the DataFrame.
(iii) Write Python statement to add a new column Total_Sales which is the addition of all the 4 quarter sales.
Consider the following DataFrame df and answer any four questions from (i)-(v):
rollno name UT1 UT2 UT3 UT4 1 Prerna Singh 24 24 20 22 2 Manish Arora 18 17 19 22 3 Tanish Goel 20 22 18 24 4 Falguni Jain 22 20 24 20 5 Kanika Bhatnagar 15 20 18 22 6 Ramandeep Kaur 20 15 22 24 Write down the command that will give the following output :
roll no 6 name Tanish Goel UT1 24 UT2 24 UT3 24 UT4 24 dtype : object(a) print(df.max)
(b) print(df.max())
(c) print(df.max(axis = 1))
(d) print(df.max, axis = 1)