Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8857089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:30:30+00:00 2026-06-14T14:30:30+00:00

I have a CSV File here: http://www.filedropper.com/excel which looks like this http://pastebin.com/ammzv4FK . What

  • 0

I have a CSV File here: http://www.filedropper.com/excel which looks like this http://pastebin.com/ammzv4FK.

What I want to do is this:

Take each year with its corresponding rows and find the numbers in months and total them and assign them to variables.

So the first year, 2000, the list would look like this:

year2000 = ['14744', '2947', '14905', '1748',  '2859',  '11778', '1453',  '5255', '14806', '1858', '10763', '6000']

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.

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:

['2000, 14744, 2947, 14905, 1748,  2859,  11778, 1453,  5255, 14806, 1858, 10763, 6000']

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.

Here is my code:

with open("file.csv","r") as f:
    for i in range(1): 
        next(f)
    for x in f:
        x=x.split()
        print (x)

But when print(x) runs it prints it all, how can I store each year with its contents in a variable while excluding the actual year number?

I’m using Python 3, thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:30:32+00:00Added an answer on June 14, 2026 at 2:30 pm

    If you are getting the row like that you probably aren’t using a csv reader. You should use the csv module and store each row in a dict, with the year as the key. This only works if your data consists of integers.

    data = {}
    
    with open("data.csv") as f:
        reader = csv.reader(f, delimiter="\t")
        reader.next() # Skip header
        for row in reader:
            row = list(map(int, row))
            data[row[0]] = row[1:]
    

    To get the sum, use the built in sum function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have csv file that looks like this: artist,year,id,video_name,new_video_id,file_root_name,video_type ,,,,,, Clay Aiken,1,clay_aiken,Sorry Seems To
I have a CSV file which has the following format: id,case1,case2,case3 Here is a
I have a CSV file that goes something like this: ['Name1', '', '', '',
This is what I am trying to achieve: I have a CSV file which
I currently have a csv file that I'm parsing with an example from here:
Little Background: I have csv file which has lots of rows and each row
I have a CSV file supplied from a client which has to be parsed
I am trying to use the jQuery CSV plugin, as documented here: http://code.google.com/p/js-tables/wiki/CSV According
Please consider this javascript: $.ajax({ url:'http://ichart.finance.yahoo.com/table.csv?s=GS&a=00&b=1&c=2010&d=08&e=3&f=2012&g=d&ignore=.csv', type:'get', dataType:'jsonp', success:function(data){ alert(data); } }) The URL
Have a program that's dynamically generating an Excel file and a csv. The excel

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.