Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions chapter2/solutions/nyc_forecast_owm.py

This file was deleted.

41 changes: 41 additions & 0 deletions chapter2/solutions/nyc_forecast_real.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'''
Retrieve a day's forecast of New York City and create a graph
Using data downloaded from https://doingmathweatherforecast.ai.studio/
'''
import csv
import matplotlib.pyplot as plt


def read_csv(filename):

time_of_days = []
forecast_temperature = []

with open(filename) as f:
reader = csv.reader(f)
next(reader)
for row in reader:
# Extract only the time from date and time
time_of_day = row[0].split()[1]
time_of_days.append(time_of_day)
forecast_temperature.append(float(row[1]))

return time_of_days, forecast_temperature


def plot_forecast(time_of_day, forecast_temperature):

# time_of_day = ['4 AM', '7 AM', '10 AM', '1 PM', '4 PM', '7PM', '10 PM']
# forecast_temp = [71, 70, 74, 80, 82, 81, 76]
time_interval = range(1, len(time_of_day) + 1)

plt.plot(time_interval, forecast_temperature, 'o-')
plt.xticks(time_interval, time_of_day)
plt.show()
# Uncomment below and comment the previous line to save the image
# plt.savefig('nyc_owm_forecast.png')


if __name__ == '__main__':
time_of_day, forecast_temperature = read_csv("weather_New_York_1d_3h.csv")
plot_forecast(time_of_day, forecast_temperature)
9 changes: 9 additions & 0 deletions chapter2/solutions/weather_New_York_1d_3h.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"Local Date & Time","Temperature"
"2026-11-03 19:00","63.1"
"2026-11-03 22:00","60.3"
"2026-11-04 01:00","58.5"
"2026-11-04 04:00","57.6"
"2026-11-04 07:00","56.5"
"2026-11-04 10:00","63.7"
"2026-11-04 13:00","68.7"
"2026-11-04 16:00","67.6"