Note that there are some explanatory texts on larger screens.

plurals
  1. POTaking items from a CSV file and putting the elements in a list
    primarykey
    data
    text
    <p>I have a CSV File here: <a href="http://www.filedropper.com/excel" rel="nofollow">http://www.filedropper.com/excel</a> which looks like this <a href="http://pastebin.com/ammzv4FK" rel="nofollow">http://pastebin.com/ammzv4FK</a>. </p> <p>What I want to do is this:</p> <p>Take each year with its corresponding rows and find the numbers in months and total them and assign them to variables.</p> <p>So the first year, 2000, the list would look like this:</p> <pre><code>year2000 = ['14744', '2947', '14905', '1748', '2859', '11778', '1453', '5255', '14806', '1858', '10763', '6000'] </code></pre> <p>Then once I have that list I can convert the elements in the list from strings to integers, and sum them using the sum() command.</p> <p>I can print the rows out but I'm having trouble excluding the year number and then storing the rest into variables because my list comes out as this:</p> <pre><code>['2000, 14744, 2947, 14905, 1748, 2859, 11778, 1453, 5255, 14806, 1858, 10763, 6000'] </code></pre> <p>as one big string, instead of individual elements, and my list prints all the years out at once so I can't seem to figure out how to store them into variables and total them separately.</p> <p>Here is my code:</p> <pre><code>with open("file.csv","r") as f: for i in range(1): next(f) for x in f: x=x.split() print (x) </code></pre> <p>But when <code>print(x)</code> runs it prints it all, how can I store each year with its contents in a variable while excluding the actual year number?</p> <p>I'm using Python 3, thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload