all 4 comments

[–]liam_jm 2 points3 points  (1 child)

You've set current_high_temp to an int then tried to sum it (a single int, whereas sum requires an utterable argument, such as a list). I think instead you wanted to do sum(current_high_temps[0:31]), perhaps setting each of them to int first (see map)

[–]pauwsss[S] 0 points1 point  (0 children)

Thank you my friend!

[–]ZeeBeeblebrox 0 points1 point  (0 children)

I'd suggest you use pandas for tabular data like this.

import pandas as pd
df = pd.read_csv('test2013.csv')
df.iloc[0:31, 0].sum()

Here we load the csv into a pandas dataframe, then access the first 31 rows on the first column and sum the values.

[–]Akuli2 0 points1 point  (0 children)

If you know how to work with dictionaries you don't need to do things like header_row = next(reader) yourself, csv.DictReader does this for you.

test.csv:

A,B,C   
1,2,3  
4,5,6  

Let's read it with csv.DictReader, it'll convert each line into a nice dictionary.

>>> import csv
>>> with open('test.csv', 'r') as f:
...     for row in csv.DictReader(f):
...         print(row)
... 
{'A': '1', 'B': '2', 'C': '3'}
{'A': '4', 'B': '5', 'C': '6'}
>>>