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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:37:47+00:00 2026-06-05T03:37:47+00:00

I want to perform multiple edits to most rows in a csv file without

  • 0

I want to perform multiple edits to most rows in a csv file without making multiple writes to the output csv file.

I have a csv that I need to convert and clean up into specific format for another program to use. For example, I’d like to:

  1. remove all blank rows
  2. remove all rows where the value of column “B” is not a number
  3. with this new data, create a new column and explode the first part of the values in column B into the new column

Here’s an example of the data:

"A","B","C","D","E"
"apple","blah","1","","0.00"
"ape","12_fun","53","25","1.00"

"aloe","15_001","51","28",2.00"

I can figure out the logic behind each process, but what I can’t figure out is how to perform each process without reading and writing to a file each time. I’m using the CSV module. Is there a better way to perform these steps at once before writing a final CSV?

  • 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-05T03:37:48+00:00Added an answer on June 5, 2026 at 3:37 am

    I would define a set of tests and a set of processes.

    If all tests pass, all processes are applied, and the final result is written to output:

    import csv
    
    #
    # Row tests
    #
    
    def test_notblank(row):
        return any(len(i) for i in row)
    
    def test_bnumeric(row):
        return row[1].isdigit()
    
    def do_tests(row, tests=[test_notblank, test_bnumeric]):
        return all(t(row) for t in tests)
    
    #
    # Row processing
    #
    
    def process_splitb(row):
        b = row[1].split('.')
        row[1] = b[0]
        row.append(b[1])
        return row
    
    def do_processes(row, processes=[process_splitb]):
        for p in processes:
            row = p(row)
        return row
    
    def main():
        with open("in.csv","rb") as inf, open("out.csv","wb") as outf:
            incsv = csv.reader(inf)
            outcsv = csv.writer(outf)
    
            outcsv.writerow(incsv.next())    # pass header row
            outcsv.writerows(do_processes(row) for row in incsv if do_tests(row))
    
    if __name__=="__main__":
        main()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a client-side interface that allows the user to perform multiple edits against
I have multiple textboxes which I want them to perform the same thing upon
I have an input field (text) that I want to perform autocomplete on with
I have a form on an HTML page with multiple submit buttons that perform
Whenever I execute a linux command that outputs multiple lines, I want to perform
I want to perform simple validation against multiple fields. Please note these fields are
I want to perform an update on all the rows in an XML column
I have to perform multiple elaborate sanity checks on target system before an RPM
I have these classes that I use to create objects that I want to
I have a windows form that creates multiple console applications of the same program

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.