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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:46:34+00:00 2026-05-27T09:46:34+00:00

I have a CSV file with 237 lines of transactions, I’ve already figured out

  • 0

I have a CSV file with 237 lines of transactions, I’ve already figured out to group, sort, and create a new CSV file with the transactions in the correct order sorted by account number. However I’d like to go one step further and create multiple CSV files based on the account number with all of that account number’s transactions.

I think what I’d like to do just append each line to the appropiate CSV file based on the account number, but I’d like to do this dynamically so I don’t have to create each variable since there is always an unknown number of account numbers.

Account #, Date, Dollar Amount (stored as heading)
001, 1/1/11, $25
001, 1/1/11, $20
002, 1/1/11, $15
003, 1/4/11, $19

So with this data I’d like to create three separate CSV files based on the Account number. I am not looking for someone to write the code, but I am hoping there is some module in Python I’m unaware of that involves this type of process. If someone could please point me in the right direction I’d greatly appreciate it.

Thank you

  • 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-27T09:46:35+00:00Added an answer on May 27, 2026 at 9:46 am

    This is a quick (and probably not so efficient) solution.

    from sets import Set
    import csv
    
    source = list(csv.reader(open("account_file.csv")))
    
    accounts = Set(line[0] for line in source)
    
    for account in accounts:
        out = open(account+".csv","w")
        out.write( "\n".join(",".join(x) for x in source if x[0] == account))
        out.close()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two csv file ( ) I can get it to print out
I have a .csv file where I'd like to delete the lines between line
I have csv file with 14 columns and I want to sort it in
I have a CSV file with many columns. I am trying to sort the
I have CSV file and Macro in VBA. I want to open CSV file
I have .csv file that contain 2 columns delimited with , . file.csv word1,word2
Little Background: I have csv file which has lots of rows and each row
i have csv files, java app and database, i read csv file from my
How to read and import .csv file in groovy on grails. I have .csv
I have a CSV file supplied from a client which has to be parsed

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.