Q. From the dataframe object created in previous question, write a script to calculate :


(a) Average temperatures for each day of the week i.e., average temperature for Mondays, Tuesdays

and so on.


(b) Average temperature per week.


(c) Average temperature of whole month.


Answer =

(a)
print( df.mean(axis = 1, skipna = True) )

(b)
print( df.mean(axis = 0, skipna = True) )

(c)

n=df.isna().sum().sum() #Counting NaN values under an entire DataFrame:
print( df.sum().sum()/(28-n) ) # 28 is number of days in DataFrame

#OR

print( df.stack().mean() )

3 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. Can't we use any other function instead of stack () as it is not in my syllabus and teacher won't allow me to use this function.....
    Please help !!

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post