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 960383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:10:29+00:00 2026-05-16T01:10:29+00:00

I am reading a csv file into a variable data like this: def get_file(start_file):

  • 0

I am reading a csv file into a variable data like this:

def get_file(start_file): #opens original file, reads it to array
    with open(start_file,'rb') as f:
        data=list(csv.reader(f))

data is the entire csv file. How do I add an extra column to this data?

  • 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-05-16T01:10:30+00:00Added an answer on May 16, 2026 at 1:10 am

    Short answer: open up the CSV file in your favourite editor and add a column

    Long answer: well, first, you should use csv.reader to read the file; this handles all the details of splitting the lines, malformed lines, quoted commas, and so on. Then, wrap the reader in another method which adds a column.

    def get_file( start_file )
        f = csv.reader( start_file )
            def data( csvfile ):
                for line in csvfile:
                     yield line + [ "your_column" ]
        return data( f )
    

    Edit

    As you asked in your other question:

    def get_file( start_file )
        f = csv.reader( start_file )
            def data( csvfile ):
                for line in csvfile:
                    line[ 1 ] += "butter"
                    yield line
        return data( f )
    

    which you use like

    lines = get_file( "my_file.csv" )
    for line in lines:
        # do stuff
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 490k
  • Answers 490k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First of all, it's a really bad idea to use… May 16, 2026 at 9:17 am
  • Editorial Team
    Editorial Team added an answer If you are not dead set on using a listbox,… May 16, 2026 at 9:17 am
  • Editorial Team
    Editorial Team added an answer killproc will terminate programs in the process list which match… May 16, 2026 at 9:17 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

i am reading a csv file into a data: def get_file(start_file): #opens original file,
i am reading a csv file into a list of a list in python.
I am having trouble reading a csv file, delimited by tabs, in python. I
I need to import a large CSV file into an SQL server. I'm using
I am trying to merge several data.frames into one data.frame . Since I have
FileHelpers supports a feature called RunTime Records which lets you read a CSV file
I'm trying to parse the title tag in an RSS 2.0 feed into three
My company has a problem: we suspect that the NACHA files we are receiving
I'm writing a small app to do a little processing on some cells in

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.