Code, Python

Historical weather in Austin, TX

First try at running data analysis using Python to access an Excel workbook, extract the relevant information, and display it in a graph using pyplot.

First is to import the scv module, pyplot, read through the excel sheet and enter the high temperature and the current date into lists.

import csv

from matplotlib import pyplot as pt

from datetime import datetime

filename = 'austin_weather.csv'

with open(filename) as f:

                reader = csv.reader(f)

                header_row = next(reader)

                print(header_row)

                highs, dates = [],[]

                for row in reader:

                                high = float(row[3])

                                highs.append(high)

                               current_date = datetime.strptime(row[2], "%Y%m%d")

                                dates.append(current_date)           

                print(highs)

                print(dates)

Then a simple matter of setting up the graph, specifying some fun options such as the fontsize and the color of the line, the showing the graph as the final option.

fi = pt.figure(dpi=128, figsize=(8,5))

pt.plot(dates, highs, c='blue')

pt.title('Daily rain in Austin, TX', fontsize = 24)

pt.xlabel('',fontsize=12)

fi.autofmt_xdate()

pt.ylabel('Rainfall (Inches)',fontsize=12)

pt.tick_params(axis='both',which='major',labelsize=12)

pt.show()

Leave a Reply

Your email address will not be published. Required fields are marked *