Skip to content Skip to sidebar Skip to footer

Separating A Dataframe By Date And Calculating Mathmetical Models Numpy Python

The data_list and the monthly_values array are in correlation with each other, so the data point '2019-09-01 00:00:00'= 15 , 2019-10-01 00:00:00'= 39.6... etc. The year_changes fun

Solution 1:

Try via groupby(),agg(),droplevel() and rename():

out=(data.groupby(data["Date"].dt.year)
     .agg(['mean','median','max','min'])
     .droplevel(0,1)
     .rename(columns=lambda x:'Average'if x=='mean'else x.title()))

OR

via pivot_table(),droplevel() and rename():

out=(data.pivot_table('Averages',data["Date"].dt.year,aggfunc=['mean','median','max','min'])
         .droplevel(1,1)
         .rename(columns=lambda x:'Average'if x=='mean'else x.title()))

output of out:

AverageMedianMaxMinDate2019    22.27500024.6539.60.22020    14.15833314.0526.82.32021    18.7428575.0093.9-16.5

Post a Comment for "Separating A Dataframe By Date And Calculating Mathmetical Models Numpy Python"