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

  • Home
  • SEARCH
  • 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 7820115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:10:19+00:00 2026-06-02T07:10:19+00:00

I have 125 data files containing two columns and 21 rows of data and

  • 0

I have 125 data files containing two columns and 21 rows of data and I’d like to import them into a single .csv file (as 125 pairs of columns and only 21 rows).
This is what my data files look like:

enter image description here

I am fairly new to python but I have come up with the following code:

import glob
Results = glob.glob('./*.data')
fout='c:/Results/res.csv'
fout=open ("res.csv", 'w')
 for file in Results:
 g = open( file, "r" )
 fout.write(g.read())
 g.close() 
fout.close()

The problem with the above code is that all the data are copied into only two columns with 125*21 rows.

Any help is very much appreciated!

  • 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-02T07:10:21+00:00Added an answer on June 2, 2026 at 7:10 am

    This should work:

    import glob
    
    files = [open(f) for f in glob.glob('./*.data')] #Make list of open files
    fout = open("res.csv", 'w')
    
    for row in range(21):
        for f in files:
            fout.write( f.readline().strip() ) # strip removes trailing newline
            fout.write(',')
        fout.write('\n')
    
    fout.close()
    

    Note that this method will probably fail if you try a large number of files, I believe the default limit in Python is 256.

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

Sidebar

Related Questions

I have 125 data files containing two columns and 21 rows of data. Please
I have a file with structure like this: [05:58:10 08.12.1990] 125.441 [05:58:21 08.12.1990] -2.4158
I have a column filled with data in those rows and i would like
I need to read in two large files (over 125 MB). Each file contains
I bought Kibot's stock data and it is enormous. I have about 125,000,000 rows
I have a file url that outputs like: // data = { 'ip': '',
Say I have a file with any number of lines, say, 125. I want
I am experimenting with loading CSV in PHP. I have a CSV file, with
hii every one i have created a data entry screen like this in which
We have an old application that reads in SQL text files and sends them

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.