Untitled

 avatar
unknown
plain_text
a year ago
1.6 kB
4
Indexable
!pip install ipywidgets

import pandas as pd
import matplotlib.pyplot as plt
from ipywidgets import interact
from datetime import datetime

# Data setup
data = {
    'Month': ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
    'Sunrise': ['07:30', '07:05', '06:25', '06:45', '06:10', '06:05', '06:15', '06:30', '06:50', '07:10', '07:30', '07:45'],
    'Sunset': ['17:40', '18:10', '19:35', '20:05', '20:35', '20:50', '20:45', '20:15', '19:30', '18:45', '17:10', '17:00'],
    'Avg_High_Temp': [49, 54, 63, 72, 80, 88, 93, 92, 84, 73, 61, 51],
    'Avg_Low_Temp': [29, 33, 41, 50, 60, 69, 73, 72, 64, 52, 41, 32],
    'Precipitation': [1.5, 1.6, 2.8, 3.2, 5.1, 4.3, 2.9, 2.7, 3.1, 3.3, 2.1, 1.8]
}

# Create DataFrame
df = pd.DataFrame(data)

# Convert Sunrise and Sunset times to datetime objects for easier manipulation
df['Sunrise'] = pd.to_datetime(df['Sunrise'], format='%H:%M').dt.time
df['Sunset'] = pd.to_datetime(df['Sunset'], format='%H:%M').dt.time

# Interactive function
def show_weather_info(month):
    month_index = df['Month'].tolist().index(month)
    row = df.iloc[month_index]

    print(f"Weather information for {month} in Oklahoma City:")
    print(f"Sunrise: {row['Sunrise']}")
    print(f"Sunset: {row['Sunset']}")
    print(f"Average High Temperature: {row['Avg_High_Temp']} °F")
    print(f"Average Low Temperature: {row['Avg_Low_Temp']} °F")
    print(f"Average Precipitation: {row['Precipitation']} inches")

# Create interactive widget
interact(show_weather_info, month=df['Month'])
Editor is loading...
Leave a Comment