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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:45:54+00:00 2026-06-02T09:45:54+00:00

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

  • 0

I have 125 data files containing two columns and 21 rows of data. Please see the image below:

enter image description here

and I’d like to import them into a single .csv file (as 250 columns and 21 rows).

I am fairly new to python but this what I have been advised, code wise:

import glob
Results = [open(f) for f in glob.glob("*.data")] 
fout = open("res.csv", 'w')

for row in range(21):
 for f in Results:
  fout.write( f.readline().strip() ) 
  fout.write(',')
 fout.write('\n')
fout.close()

However, there is slight problem with the code as I only get 125 columns, (i.e. the force and displacement columns are written in one column) Please refer to the image below:
enter image description here

enter image description here

I’d very much appreciate it if anyone could help me with this !

  • 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-02T09:45:57+00:00Added an answer on June 2, 2026 at 9:45 am
    import glob
    results = [open(f) for f in glob.glob("*.data")]
    sep = ","
    # Uncomment if your Excel formats decimal numbers like 3,14 instead of 3.14
    # sep = ";"
    
    with open("res.csv", 'w') as fout:
        for row in range(21):
            iterator = (f.readline().strip().replace("\t", sep) for f in results)
            line = sep.join(iterator)
            fout.write("{0}\n".format(line))
    

    So to explain what went wrong with your code, your source files use tab as a field separator, but your code uses comma to separate the lines it reads from those files. If your excel uses period as a decimal separator, it uses comma as a default field separator. The whitespace is ignored unless enclosed in quotes, and you see the result.

    If you use the text import feature of Excel (Data ribbon => From Text) you can ask it to consider both comma and tab as valid field separators, and then I’m pretty sure your original output would work too.

    In contrast, the above code should produce a file that will open correctly when double clicked.

    • 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 and
I have a column filled with data in those rows and i would like
I bought Kibot's stock data and it is enormous. I have about 125,000,000 rows
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 need to read in two large files (over 125 MB). Each file contains
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
I have over 125 TSV files of ~100Mb each that I want to merge.
Okay so I have two png files, a circle and a maze. Basically the
Say you have an IP address: 74.125.45.100 so its A.B.C.D Is there a way

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.