Informatics Practices
Write Python code to create a Series object Temp2 storing temperatures of seven days of week. Its indexes should be 'Sunday', 'Monday',… 'Saturday'.
Python Pandas
4 Likes
Answer
import pandas as pd
temperatures = [28.9, 30.1, 26.2, 29.3, 27.5, 31.9, 25.5]
days_of_week = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
Temp2 = pd.Series(temperatures, index = days_of_week)
print(Temp2)Output
Sunday 28.9
Monday 30.1
Tuesday 26.2
Wednesday 29.3
Thursday 27.5
Friday 31.9
Saturday 25.5
dtype: float64
Answered By
2 Likes
Related Questions
Find the error in the following code considering the same dataframe topDf given in the previous question.
(i) topDf.rename(index=['a', 'b', 'c', 'd'])
(ii) topDf.rename(columns = {})
Write Python code to create a Series object Temp1 that stores temperatures of seven days in it. Take any random seven temperatures.
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.
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.