Weather
import pandas as pd
import matplotlib.pyplot as plt
# Data for New York hourly forecast
data = {
"Time": ["3 PM", "6 PM", "9 PM", "12 AM", "3 AM", "6 AM", "9 AM", "12 PM", "3 PM"],
"Temp (°C)": [26, 24, 23, 22, 21, 20, 23, 28, 28],
"Temp (°F)": [79, 75, 73, 72, 70, 68, 73, 82, 82],
"Condition": [
"Mostly sunny", "Clear", "Clear", "Clear", "Clear", "Sunny",
"Mostly sunny", "Sunny and warm", "Continued warmth"
]
}
df = pd.DataFrame(data)
# Display styled table with color
def color_temp(val):
if isinstance(val, (int, float)):
if val >= 28:
return 'background-color: #ff9999' # hot
elif val >= 24:
return 'background-color: #ffd699' # warm
elif val >= 20:
return 'background-color: #ffffb3' # mild
else:
return 'background-color: #c2f0c2' # cool
return ''
styled_df = df.style.applymap(color_temp, subset=["Temp (°C)", "Temp (°F)"])
import caas_jupyter_tools as tools; tools.display_dataframe_to_user(name="New York 24-Hour Forecast", dataframe=df)
styled_df
0 Comments