Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, I am working on a Python project. For the project, I have to read temperatur

ID: 3917678 • Letter: H

Question

Hi, I am working on a Python project. For the project, I have to read temperatures (average monthly temperatures from 2000-2018 in four cities) from a csv file, convert the temperatures from Celsius to Fahrenheit, and graph all the data on one graph. This is what I have so far: import csv import numpy as np import matplotlib.pyplot as plt def main(): open(data.csv, "r") Oslo =[] Harrisburg =[] Honolulu =[] Santiago =[] new_array=[] for year in range(2000,2018): for month in range(1,12): Oslo.append(value1) Harrisburg.append(value2) Honolulu.append(value3) Santaiago.append(value4) new_array.append(year) plt.plot(new_array, Oslo, 'b-', label = "Oslo") plt.plot(new_array, Harrisburg, 'r-', label = "Harrisburg") plt.plot(new_array, Honolulu, 'g-', label = "Honolulu") plt.plot(new_array, Santiago, 'y-', label = "Santiago") plt.legend(shadow = True, loc = "best") plt.xticks(np.arange(0, 216, 1.0)) plt.yticks(np.arange(min(temperature), max(temperature), 10.0)) plt.xlabel('Year') plt.ylabel('Temperature') plt.title("Average Monthly Temperature in Four Cities") plt.show() main() I think my main obstacle right now is how to open the csv file, because when I try to run the program, I get an error that says: "NameError: name 'data' is not defined". Any help is greatly appreciated. Thank you.

Explanation / Answer

Dear just put quotes around the file name i.e. 'data.csv' and it will be done. File names are strings and supposed to be treated like that.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote