Python danna yaluwangen help ekak oni

Hachiko15

Well-known member
  • Jul 17, 2018
    795
    398
    63
    contains hourly weather observations

    The file named : weather_2021-12.csv

    | Abbreviation | Meaning |
    | --- | --- |
    | TA | Temperature Average |
    | RH | Relative Humidity |
    | WS | Wind Speed |
    | WD | Wind Direction |
    | PRA | Precipitation Amount |
    | PRI | Precipitation Intensity |
    | PA | Pressure Average |
    | WAWA | Most Significant Weather Code |


    Calculate the average relative humidity over the full timespan covered in the data, dropping any NaN values.

    Please also write a separate report (Jupyter notebook) about solving Exercise


    Yaluwane mata meka
    Python (Jupyter notebook) wlain karagnna help ekak denwada? python danna yaluwo innawanm
     

    Hachiko15

    Well-known member
  • Jul 17, 2018
    795
    398
    63
    Gemini ට කියපන් මචං. වැඩේ ඉක්මනට කරගන්න පුළුවන්
    Thanks bro try ekak dennam

    Code:
    import pandas as pd
       
        data = pd.read_csv(r'C:\Users\Dataset\weather_2021-12.csv')
       
        relative_humidity_data = data[data["ParameterName"] == "RH_PT1H_AVG"]
       
        average_relative_humidity = relative_humidity_data["ParameterValue"].mean()
       
        print("The average relative humidity is:", average_relative_humidity)


    meka harida result eka The average relative humidity is: 88.32212885154061
    ------ Post added on Feb 20, 2024 at 12:05 PM
     
    Last edited:

    chamoda4lk

    Active member
  • Feb 18, 2010
    765
    149
    43
    The code above is correct. This non-Pandas version returns the same answer.

    Python:
    from csv import DictReader
    
    with open("weather_2021-12.csv") as f:
        reader = DictReader(f)
        relative_humidity_values = [
            float(row["ParameterValue"]) for row in reader
            if row["ParameterName"] == "RH_PT1H_AVG" and row["ParameterValue"] != "NaN"
        ]
        average_relative_humidity = sum(relative_humidity_values) / len(relative_humidity_values)
        print(average_relative_humidity)
     
    • Love
    Reactions: Hachiko15

    EKGuest

    Well-known member
  • Nov 16, 2022
    3,206
    5,703
    113
    meka harida result eka The average relative humidity is: 88.32212885154061

    ඔය උත්තරේ හරි මම C# වලින් කරලා බැලුවා උත්තරේ එන්නේ 88.32212885154061624649859944
     
    • Love
    Reactions: Hachiko15

    Hachiko15

    Well-known member
  • Jul 17, 2018
    795
    398
    63
    ඔය උත්තරේ හරි මම C# වලින් කරලා බැලුවා උත්තරේ එන්නේ 88.32212885154061624649859944
    Thanks bro

    The code above is correct. This non-Pandas version returns the same answer.

    Python:
    from csv import DictReader
    
    with open("weather_2021-12.csv") as f:
        reader = DictReader(f)
        relative_humidity_values = [
            float(row["ParameterValue"]) for row in reader
            if row["ParameterName"] == "RH_PT1H_AVG" and row["ParameterValue"] != "NaN"
        ]
        average_relative_humidity = sum(relative_humidity_values) / len(relative_humidity_values)
        print(average_relative_humidity)
    Thanks bro
    ------ Post added on Feb 20, 2024 at 1:44 PM