Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
එක පැකේජ් එකයි මාසෙටම Unlimited Internet. තාමත් DATA CARD දාන්න සල්ලි වියදම් කරනවද? අඩුම මිලට අපෙන්.
sayuru bandara
Updated:
Tuesday at 12:30 PM
Ad icon
ඉන්ටර්නෙට් එකෙන් හරියටම සල්ලි හොයන්න සහ Success වෙන්න කැමතිද? 🚀 (E-Money & Success Stories)
siri sumana
Updated:
Saturday at 11:44 PM
Gemini AI PRO 18 months Offer
Hawaka
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Help
Python Help
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="Hachiko15" data-source="post: 29617819" data-attributes="member: 568034"><p>Yaluwane help ekak dennako meka karagnna</p><p>mata poddak meka karana vidiya kiya dunnaam ethi</p><p>Python walin</p><p></p><p></p><p></p><p>A file named</p><p></p><p></p><p><strong>weather_2023-02.csv</strong></p><p></p><p>contains hourly weather observations</p><p></p><p></p><table style='width: 100%'><tr><th>Abbreviation</th><th>Meaning</th></tr><tr><td>TA</td><td>Temperature Average</td></tr><tr><td>RH</td><td>Relative Humidity</td></tr><tr><td>WS</td><td>Wind Speed</td></tr><tr><td>WD</td><td>Wind Direction</td></tr><tr><td>PRA</td><td>Precipitation Amount</td></tr><tr><td>PRI</td><td>Precipitation Intensity</td></tr><tr><td>PA</td><td>Pressure Average</td></tr><tr><td>WAWA</td><td>Most Significant Weather Code</td></tr></table><p></p><p>Some of the data has been encrypted with your GPG public key. Ignoring any NaN values, find out what percentage of the hourly temperature observations satisfy the following:</p><p></p><p></p><p></p><p>mama try kara hari giye na</p><p></p><p></p><p>[CODE]import pandas as pd</p><p>from cryptography.fernet import Fernet, InvalidToken</p><p></p><p># Function to generate or load Fernet key</p><p>def load_or_generate_key():</p><p> try:</p><p> # Load the key if exists</p><p> with open("fernet_key.key", "rb") as key_file:</p><p> key = key_file.read()</p><p> except FileNotFoundError:</p><p> # Generate a new key if not exists</p><p> key = Fernet.generate_key()</p><p> with open("fernet_key.key", "wb") as key_file:</p><p> key_file.write(key)</p><p> return key</p><p></p><p># Decrypt the column headers and relevant data</p><p>def decrypt_weather_data(file_path, key):</p><p> f = Fernet(key)</p><p> try:</p><p> with open(file_path, "rb") as encrypted_file:</p><p> encrypted_data = encrypted_file.read()</p><p> decrypted_data = f.decrypt(encrypted_data)</p><p> # Decode the decrypted data as UTF-8 and split it into lines</p><p> decrypted_lines = decrypted_data.decode("utf-8").split("\n")</p><p> # Extract column headers</p><p> column_headers = decrypted_lines[0].split(",")</p><p> # Extract relevant data</p><p> data = []</p><p> for line in decrypted_lines[1:]:</p><p> if line.strip(): # Skip empty lines</p><p> row = line.split(",")</p><p> if len(row) == len(column_headers): # Ensure the row has the correct number of columns</p><p> data.append(row)</p><p> return column_headers, data</p><p> except InvalidToken:</p><p> print("Error: Invalid decryption key or corrupt file.")</p><p> return None, None</p><p></p><p># Main function</p><p>def main():</p><p> # Load or generate Fernet key</p><p> key = load_or_generate_key()</p><p></p><p> # Decrypt the weather data</p><p> file_to_decrypt = 'D:Assignment\\weather_2023-02.csv.encrypted'</p><p> column_headers, data = decrypt_weather_data(file_to_decrypt, key)</p><p></p><p> if column_headers and data:</p><p> # Create DataFrame from decrypted data</p><p> df = pd.DataFrame(data, columns=column_headers)</p><p></p><p> # Check if expected columns exist</p><p> expected_cols = ['TA_PT1H_MAX', 'TA_PT1H_MIN']</p><p> if not all(col in df.columns for col in expected_cols):</p><p> missing_cols = [col for col in expected_cols if col not in df.columns]</p><p> print(f"Error: Expected columns {', '.join(missing_cols)} not found in data.")</p><p> return</p><p></p><p> # Extract relevant columns</p><p> df_filtered = df[expected_cols]</p><p></p><p> # Calculate temperature differences</p><p> df_filtered['temp_diff'] = df_filtered['TA_PT1H_MAX'] - df_filtered['TA_PT1H_MIN']</p><p></p><p> # Handle NaN values</p><p> df_filtered = df_filtered.dropna()</p><p></p><p> # Calculate mean and standard deviation</p><p> mean_diff = df_filtered['temp_diff'].mean()</p><p> std_diff = df_filtered['temp_diff'].std()</p><p></p><p> # Identify observations within the specified range</p><p> filtered_df = df_filtered[(df_filtered['temp_diff'] >= mean_diff - 0.6 * std_diff) & (df_filtered['temp_diff'] <= mean_diff + 0.6 * std_diff)]</p><p></p><p> # Calculate the percentage</p><p> percentage = (filtered_df.shape[0] / df_filtered.shape[0]) * 100</p><p></p><p> print("Column Headers:")</p><p> print(column_headers)</p><p> print("\nFirst Few Rows of Decrypted Data:")</p><p> print(df.head()) # Display the first few rows of the DataFrame</p><p> print("\nPercentage of observations satisfying the condition:", percentage)</p><p> else:</p><p> print("Decryption failed or no data found.")</p><p></p><p>if __name__ == "__main__":</p><p> main()</p><p>[/CODE]</p><p></p><p>OutPut</p><p><span style="color: rgb(184, 49, 47)">Error: Expected columns TA_PT1H_MAX, TA_PT1H_MIN not found in data.</span></p></blockquote><p></p>
[QUOTE="Hachiko15, post: 29617819, member: 568034"] Yaluwane help ekak dennako meka karagnna mata poddak meka karana vidiya kiya dunnaam ethi Python walin A file named [B]weather_2023-02.csv[/B] contains hourly weather observations [TABLE] [TR] [TH]Abbreviation[/TH] [TH]Meaning[/TH] [/TR] [TR] [TD]TA[/TD] [TD]Temperature Average[/TD] [/TR] [TR] [TD]RH[/TD] [TD]Relative Humidity[/TD] [/TR] [TR] [TD]WS[/TD] [TD]Wind Speed[/TD] [/TR] [TR] [TD]WD[/TD] [TD]Wind Direction[/TD] [/TR] [TR] [TD]PRA[/TD] [TD]Precipitation Amount[/TD] [/TR] [TR] [TD]PRI[/TD] [TD]Precipitation Intensity[/TD] [/TR] [TR] [TD]PA[/TD] [TD]Pressure Average[/TD] [/TR] [TR] [TD]WAWA[/TD] [TD]Most Significant Weather Code[/TD] [/TR] [/TABLE] Some of the data has been encrypted with your GPG public key. Ignoring any NaN values, find out what percentage of the hourly temperature observations satisfy the following: mama try kara hari giye na [CODE]import pandas as pd from cryptography.fernet import Fernet, InvalidToken # Function to generate or load Fernet key def load_or_generate_key(): try: # Load the key if exists with open("fernet_key.key", "rb") as key_file: key = key_file.read() except FileNotFoundError: # Generate a new key if not exists key = Fernet.generate_key() with open("fernet_key.key", "wb") as key_file: key_file.write(key) return key # Decrypt the column headers and relevant data def decrypt_weather_data(file_path, key): f = Fernet(key) try: with open(file_path, "rb") as encrypted_file: encrypted_data = encrypted_file.read() decrypted_data = f.decrypt(encrypted_data) # Decode the decrypted data as UTF-8 and split it into lines decrypted_lines = decrypted_data.decode("utf-8").split("\n") # Extract column headers column_headers = decrypted_lines[0].split(",") # Extract relevant data data = [] for line in decrypted_lines[1:]: if line.strip(): # Skip empty lines row = line.split(",") if len(row) == len(column_headers): # Ensure the row has the correct number of columns data.append(row) return column_headers, data except InvalidToken: print("Error: Invalid decryption key or corrupt file.") return None, None # Main function def main(): # Load or generate Fernet key key = load_or_generate_key() # Decrypt the weather data file_to_decrypt = 'D:Assignment\\weather_2023-02.csv.encrypted' column_headers, data = decrypt_weather_data(file_to_decrypt, key) if column_headers and data: # Create DataFrame from decrypted data df = pd.DataFrame(data, columns=column_headers) # Check if expected columns exist expected_cols = ['TA_PT1H_MAX', 'TA_PT1H_MIN'] if not all(col in df.columns for col in expected_cols): missing_cols = [col for col in expected_cols if col not in df.columns] print(f"Error: Expected columns {', '.join(missing_cols)} not found in data.") return # Extract relevant columns df_filtered = df[expected_cols] # Calculate temperature differences df_filtered['temp_diff'] = df_filtered['TA_PT1H_MAX'] - df_filtered['TA_PT1H_MIN'] # Handle NaN values df_filtered = df_filtered.dropna() # Calculate mean and standard deviation mean_diff = df_filtered['temp_diff'].mean() std_diff = df_filtered['temp_diff'].std() # Identify observations within the specified range filtered_df = df_filtered[(df_filtered['temp_diff'] >= mean_diff - 0.6 * std_diff) & (df_filtered['temp_diff'] <= mean_diff + 0.6 * std_diff)] # Calculate the percentage percentage = (filtered_df.shape[0] / df_filtered.shape[0]) * 100 print("Column Headers:") print(column_headers) print("\nFirst Few Rows of Decrypted Data:") print(df.head()) # Display the first few rows of the DataFrame print("\nPercentage of observations satisfying the condition:", percentage) else: print("Decryption failed or no data found.") if __name__ == "__main__": main() [/CODE] OutPut [COLOR=rgb(184, 49, 47)]Error: Expected columns TA_PT1H_MAX, TA_PT1H_MIN not found in data.[/COLOR] [/QUOTE]
Insert quotes…
Verification
Dahaya deken beduwama keeyada?
Post reply
Top
Bottom