Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
66 views3 pages

Weather Data Recorder Project

The document describes a Python program designed to record and analyze daily weather data for agricultural purposes. It includes features such as date validation, duplicate entry prevention, data storage, and CSV export functionality. Users can add weather data, view logs, analyze summaries, and export data through a simple menu-driven interface.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views3 pages

Weather Data Recorder Project

The document describes a Python program designed to record and analyze daily weather data for agricultural purposes. It includes features such as date validation, duplicate entry prevention, data storage, and CSV export functionality. Users can add weather data, view logs, analyze summaries, and export data through a simple menu-driven interface.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Weather Data Recorder for AgriWeather Insights

This Python program records and analyzes daily weather data for crop planning. It includes date

validation, prevents duplicate entries using a set, stores data in a list, uses pandas for analysis, and

can export data to a CSV file.

Python Code

import pandas as pd
from datetime import datetime

weather_data = []
unique_dates = set()

def validate_date(date_str):
try:
return datetime.strptime(date_str, "%Y-%m-%d").date()
except ValueError:
return None

def add_weather_data():
date_str = input("Enter date (YYYY-MM-DD): ")
date = validate_date(date_str)
if not date:
print("[ERROR] Invalid date format.")
return
if date_str in unique_dates:
print("[WARNING] Entry for this date exists.")
return
try:
temperature = float(input("Enter temperature (°C): "))
except ValueError:
print("[ERROR] Invalid temperature.")
return
condition = input("Enter weather condition: ").capitalize()
weather_data.append({
"Date": date_str,
"Temperature (°C)": temperature,
"Condition": condition
})
unique_dates.add(date_str)
print("[OK] Weather data added.")

def view_weather_data():
if not weather_data:
print("No data recorded.")
return
df = pd.DataFrame(weather_data)
print("\n[LOG] Weather Log:\n", df)
def show_summary():
if not weather_data:
print("No data to analyze.")
return
df = pd.DataFrame(weather_data)
avg_temp = df["Temperature (°C)"].mean()
print(f"\n[SUMMARY] Average Temperature: {avg_temp:.2f} °C")

def export_to_csv(filename="weather_data.csv"):
if not weather_data:
print("No data to export.")
return
df = pd.DataFrame(weather_data)
df.to_csv(filename, index=False)
print(f"[OK] Data exported to {filename}")

def main():
while True:
print("\n--- AgriWeather Data Recorder ---")
print("1. Add Weather Data")
print("2. View Weather Log")
print("3. Show Summary")
print("4. Export to CSV")
print("5. Exit")
choice = input("Enter choice (1-5): ")
if choice == '1':
add_weather_data()
elif choice == '2':
view_weather_data()
elif choice == '3':
show_summary()
elif choice == '4':
export_to_csv()
elif choice == '5':
print("Exiting... Goodbye!")
break
else:
print("[ERROR] Invalid choice. Try again.")

if __name__ == "__main__":
main()

Sample Output

--- AgriWeather Data Recorder ---


1. Add Weather Data
2. View Weather Log
3. Show Summary
4. Export to CSV
5. Exit
Enter choice (1-5): 1
Enter date (YYYY-MM-DD): 2025-07-08
Enter temperature (°C): 31.5
Enter weather condition (e.g., Sunny, Rainy): sunny
[OK] Weather data added successfully!

You might also like