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
#11
" you have been asked to find some statiscal information about tempreture and rainfull for a variety of months.

the data will be hard coded into your script, with each new set of test data added to the end of the previous data.



find out:

the mean temperature for each month
the mean rainfall for each month
the total rainfall for each month
the max and min temperatures and rainfall for each month

its not doing above ^

i am clueless -.-
Reply
#12
I'm not sure, but are you calling the things instead of for defining them in your code?
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
#13
bro, i got no idea, i only understand the syntax of python, i copy pasted the scripts and edited with whats needed(hardcode date). APart from that i have NO idea.

-.- i don't know -.- i can only apply scripts and edit after 100 horsu to get were i am, if theres a error i dont know were to look
Reply
#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
#15
ARE U SHITTING ME F*** ME< OMFGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG

THJANK YOU HEAPS I REALLY MEANI T TAHNK YOU SO MCh

line 49, in <module>
the_months_name = calendar.months_name[the_months]
AttributeError: module 'calendar' has no attribute 'months_name

shouldnt it be calender?

its giving me this error now

if its not define it would of given error before

it is defined well to my understanding
Reply
#16
See this this
According to this :
An array that represents the months of the year in the current locale. This follows normal convention of January being month number 1, so it has a length of 13 and month_name[0] is the empty string.
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
#17
AAAAAAAAAAAAAAhhhhhhhhhhhhhhhhhhhhh
Reply
#18
Also, chill on your language, It really isn't used in the forum and you may get a warning
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
#19
so i should be putting [4, 5, 6] ?

yeah sorry i was just super excited i meant well wont happen again.
Reply
#20
(May-08-2020, 11:42 AM)Lucifer Wrote: so i should be putting [4, 5, 6] ?

yeah sorry i was just super excited i meant well wont happen again.

Where?
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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Struggling on Tuples Mystix 3 4,926 Feb-01-2021, 06:06 PM
Last Post: nilamo
  Struggling with variables pythonstudy00 1 1,509 Sep-23-2020, 06:39 AM
Last Post: DPaul
  Struggling To Understand These 2 Python Files samlee916 2 1,804 Sep-22-2020, 04:50 AM
Last Post: ndc85430
  struggling w/ fonctions in Python Tiril123 7 3,888 May-09-2020, 10:51 AM
Last Post: pyzyx3qwerty
  How to change part of the value string in Python Dictionary? sbabu 11 4,172 Feb-12-2020, 02:25 AM
Last Post: sbabu
  struggling with python save/load function newatpython00 1 2,018 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