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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:25:30+00:00 2026-05-15T18:25:30+00:00

I have 2 csv files: output.csv output1.csv output.csv has a 5 columns of titles.

  • 0

I have 2 csv files:

  • output.csv
  • output1.csv

output.csv has a 5 columns of titles.
output1.csv has about 40 columns of different types of data.

I need to append all the content of output1.csv to output.csv. How can I do this?
could somebody please give me a hint on how to go about it ???
i have the following code :

reader=csv.DictReader(open("test.csv","r"))
allrows = list(reader)

keepcols = [c for c in allrows[0] if all(r[c] != '0' for r in allrows)]

print keepcols
writer=csv.DictWriter(open("output.csv","w"),fieldnames='keepcols',extrasaction='ignore')
writer.writerows(allrows)

    with open("test1.csv","r") as f:
        fields=next(f).split()
        # print(fields)
        allrows=[]
        for line in f:
            line=line.split()
            row=dict(zip(fields,line))
            allrows.append(row)
            # print(row)
        keepcols = [c for c in fields if any(row[c] != '0' for row in allrows)]
        print keepcols
        writer=csv.DictWriter(open("output1.csv","w"),fieldnames=keepcols,extrasaction='ignore')
        writer.writerows(allrows)

test.csv generates output.csv
test1.csv generates output1.csv

i m trying to see if i can make both files generate my output in the same file..

  • 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-15T18:25:31+00:00Added an answer on May 15, 2026 at 6:25 pm

    If I understand your question correctly, you want to create a csv with 41 columns – the 1 from output.csv followed by the 40 from output1.csv.
    I assume they have the same number of rows (if not – what is the necessary behavior?)

    Try using the csv module:

    import csv
    reader = csv.reader(open('output.csv', 'rb'))
    reader1 = csv.reader(open('output1.csv', 'rb'))
    writer = csv.writer(open('appended_output.csv', 'wb'))
    for row in reader:
        row1 = reader1.next()
        writer.writerow(row + row1)
    

    If your csv files are formatted with special delimiters or quoting characters, you can use the optional keyword arguments for the csv.reader and csv.writer objects.
    See Python’s csv module documentation for details…

    EDIT: Added ‘b’ flag, as suggested.

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

Sidebar

Related Questions

I have a bunch of csv files. Each has data from a different period:
I have a mapper that, while processing data, classifies output into 3 different types
I have CSV files that have multiple columns that are sorted. For instance, I
We have written a number of SSIS packages that import data from CSV files
We have a some ETL processes that read CSV files that are output from
I have a csv file which has 3 columns. I am trying to search
I have a simple .csv file that has that I want to extract data
I have a source folder which contains 4 csv files with different no of
I have csv file having some address data mostly in Finnish language. I need
I have n csv files which I need to compare against each other and

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.