Python Forum
struggling with one part of python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
struggling with one part of python
#14
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))
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply


Messages In This Thread
struggling with one part of python - by Lucifer - May-08-2020, 09:16 AM
RE: struggling with one part of python - by Lucifer - May-08-2020, 09:25 AM
RE: struggling with one part of python - by Lucifer - May-08-2020, 10:06 AM
RE: struggling with one part of python - by buran - May-08-2020, 10:09 AM
RE: struggling with one part of python - by Lucifer - May-08-2020, 10:12 AM
RE: struggling with one part of python - by buran - May-08-2020, 10:12 AM
RE: struggling with one part of python - by Lucifer - May-08-2020, 10:26 AM
RE: struggling with one part of python - by Lucifer - May-08-2020, 10:34 AM
RE: struggling with one part of python - by pyzyx3qwerty - May-08-2020, 11:17 AM
RE: struggling with one part of python - by Lucifer - May-08-2020, 11:25 AM
RE: struggling with one part of python - by Lucifer - May-08-2020, 11:39 AM
RE: struggling with one part of python - by Lucifer - May-08-2020, 11:42 AM
RE: struggling with one part of python - by Lucifer - May-08-2020, 11:54 AM
RE: struggling with one part of python - by Lucifer - May-08-2020, 12:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Struggling on Tuples Mystix 3 4,938 Feb-01-2021, 06:06 PM
Last Post: nilamo
  Struggling with variables pythonstudy00 1 1,524 Sep-23-2020, 06:39 AM
Last Post: DPaul
  Struggling To Understand These 2 Python Files samlee916 2 1,814 Sep-22-2020, 04:50 AM
Last Post: ndc85430
  struggling w/ fonctions in Python Tiril123 7 3,894 May-09-2020, 10:51 AM
Last Post: pyzyx3qwerty
  How to change part of the value string in Python Dictionary? sbabu 11 4,182 Feb-12-2020, 02:25 AM
Last Post: sbabu
  struggling with python save/load function newatpython00 1 2,028 Nov-15-2019, 07:58 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020