I got it for the months you have written month, hope you can follow this example and do for all :
import calendar
print("The calender of year 2020 is : ")
print (calendar.calendar(2020, 2, 1, 6))
import statistics # for calculation of mean
from decimal import Decimal
all_data = [];
pre_stat_data = {};
april_data = [["1/04/2019", 21.3, 26.8, 0.0], ["2/04/2019", 18.5, 29.0, 0.0], ["3/04/2019", 18.5, 30.0, 0.0]]
may_data = [["1/05/2019", 9.2, 18, 0.0], ["2/05/2019", 5.5, 19.6, 0.0], ["3/05/2019", 6.6, 27.1, 0.0]]
june_data = [["1/06/2019", 7.5, 25.5, 0.0], ["2/06/2019", 5.9, 24.5, 0.0], ["3/06/2019", 7.3, 23.9, 0.0]]
july_data = [["1/07/2019", 11.9, 20.2, 9.4], ["2/07/2019", 6.0, 20.6, 0.2], ["3/07/2019", 6.1, 21.7, 0.0]]
# create existing data list
for nlist in april_data:
row = []
for item in nlist:
row.append(item) # append item in new list
all_data.append(row)
for nlist in may_data:
row = []
for item in nlist:
row.append(item)
all_data.append(row)
for nlist in june_data:
row = []
for item in nlist:
row.append(item)
all_data.append(row)
for nlist in july_data:
row = []
for item in nlist:
row.append(item)
all_data.append(row)
for biglist in all_data:
the_month_name = ""
temp_month_dic = {}
for idx, val in enumerate(biglist):
if (idx == 0): # date changes
the_date_arr = val.split('/')
the_month = int(the_date_arr[1])
the_month_name = calendar.month_name[the_month]
# print(the_month_name);
if the_month_name in pre_stat_data:
temp_month_dic = pre_stat_data[the_month_name] # change this number to month
else:
pre_stat_data[the_month_name] = temp_month_dic
elif (idx == 1): # min temperature
if "min_temp" in temp_month_dic:
temp_month_dic["min_temp"].append(val);
else:
temp_month_dic["min_temp"] = []
temp_month_dic["min_temp"].append(val);
elif (idx == 2): # max temperature
if "max_temp" in temp_month_dic:
temp_month_dic["max_temp"].append(val);
else:
temp_month_dic["max_temp"] = []
temp_month_dic["max_temp"].append(val);
elif (idx == 3): # rainfall
if "rainfall" in temp_month_dic:
temp_month_dic["rainfall"].append(val);
else:
temp_month_dic["rainfall"] = []
temp_month_dic["rainfall"].append(val);
# print(pre_stat_data for display)
post_stat_data = {}
for key, value in pre_stat_data.items():
tempo_temp_list = []
tempo_temp_list.extend(pre_stat_data[key]["min_temp"])
tempo_temp_list.extend(pre_stat_data[key]["max_temp"])
pre_stat_data[key]["temp_list"] = tempo_temp_list;
pre_stat_data[key]["temp_final_min"] = min(pre_stat_data[key]["min_temp"])
pre_stat_data[key]["temp_final_max"] = max(pre_stat_data[key]["max_temp"])
pre_stat_data[key]["temp_final_mean"] = statistics.mean(pre_stat_data[key]["temp_list"])
pre_stat_data[key]["rain_total"] = sum(pre_stat_data[key]["rainfall"])
pre_stat_data[key]["rain_min"] = min(pre_stat_data[key]["rainfall"])
pre_stat_data[key]["rain_max"] = max(pre_stat_data[key]["rainfall"])
pre_stat_data[key]["rain_mean"] = statistics.mean(pre_stat_data[key]["rainfall"])
post_stat_data[key] = pre_stat_data[key]
del post_stat_data[key]["min_temp"]
del post_stat_data[key]["max_temp"]
del post_stat_data[key]["temp_list"]
del post_stat_data[key]["rainfall"]
# Hard coded data for processing
post_stat_data = pre_stat_data
disp_data = {"month_name": [], "temp_min": [], "temp_max": [], "temp_mean": [], "rain_total": [], "rain_min": [],
"rain_max": [], "rain_mean": []}
for key, value in post_stat_data.items():
disp_data['month_name'].append(key);
dec_min = Decimal(post_stat_data[key]["temp_final_min"]);
dec_min = round(dec_min, 2) # rounding of decimal
disp_data['temp_min'].append(dec_min)
dec_max = Decimal(post_stat_data[key]["temp_final_max"]);
dec_max = round(dec_max, 2) # rounding of decimal
disp_data['temp_max'].append(dec_max)
dec_mean = Decimal(post_stat_data[key]["temp_final_mean"]);
dec_mean = round(dec_mean, 2) # rounding of decimal
disp_data['temp_mean'].append(dec_mean)
dec_rain_total = Decimal(post_stat_data[key]["rain_total"]);
dec_rain_total = round(dec_rain_total, 2) # rounding of decimal
disp_data['rain_total'].append(dec_rain_total)
dec_rain_min = Decimal(post_stat_data[key]["rain_min"]);
dec_rain_min = round(dec_rain_min, 2) # rounding of decimal
disp_data['rain_min'].append(dec_rain_min)
dec_rain_max = Decimal(post_stat_data[key]["rain_max"]);
dec_rain_max = round(dec_rain_max, 2) # rounding of decimal
disp_data['rain_max'].append(dec_rain_max)
dec_rain_mean = Decimal(post_stat_data[key]["rain_mean"]);
dec_rain_mean = round(dec_rain_mean, 2) # rounding of decimal
disp_data['rain_mean'].append(dec_rain_mean)
# display existing data
print("Existing data table : " + str(all_data))