Question: Hi! I have a question about Python. For my project, I have to read temperatures from a csv file and create a graph with those

Hi! I have a question about Python. For my project, I have to read temperatures from a csv file and create a graph with those values. My graph needs to use the years 2000-2017 as x-axis labels, but also have tickmarks for the months. I also need to convert all the temperatures from Celsius to Fahrenheit. I assume I need to use a nested for loop to extract the data (one loop for the year and one for the month), but I am unsure how to write the loop, especially to keep the previous value when the loop runs again. Here is what I have so far:

import numpy as np import matplotlib.pyplot as plt

def main(): temps = open(data.csv, "r") for year == "2000": for month == "1": Oslo = Harrisburg = Honolulu = Santaiago = years = np.linspace(2000, 2017, 17)

plt.plot(years, Oslo, 'b-', label = "Oslo") plt.plot(years, Harrisburg, 'r-', label = "Harriburg") plt.plot(years, Honolulu, 'g-', label = "Honolulu") plt.plot(years, Santiago, 'y-', label = "Santiago") plt.legend(shadow = True, loc = "best")

plt.xticks(np.arange(0, 12, 1.0)) plt.yticks(np.arange(0, max(temperature), 10.0))

plt.xlabel('Year') plt.ylabel('Temperature')

plt.title("Average Monthly Temperature in Four Cities")

plt.show() main()

Thank you!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!