I've been told that my code is correct but I keep getting
ValueError: could not convert string to float: 'Value'"
I'm not sure where I am going wrong.
What can I do to turn data from a CSV file into a float?
Code:
filename = input("Temperature anomaly filename:")
list_temp = []
row = 0
with open(filename) as file:
for line in file:
line = line.strip("\n")
year, temp = line.split(",")
if row == 0:
list_temp.append(float(temp))
else:
list_temp.append(float(temp))
row = row + 1
k = int(input("Enter window size:"))
for index in range(k, len(list_temp)-k):
year = 1880 + index
avg = sum(list_temp[index-k:index+k+1]) / (2*k+1)
print("{}, {:.4f}".format(year, avg))
CSV data
Year,Value
1880,-1.56
1881,-0.08
1882,-0.3
...
2016,0.48
2017,2.63
2018,0.18
Input: 20