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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:15:08+00:00 2026-06-15T19:15:08+00:00

I’ve been given a load of data files (.txt) representing the data from an

  • 0

I’ve been given a load of data files (.txt) representing the data from an experiment, from one instrument. Here is an example:

141716:test: 1 width: 10distance: 13 time: 1690 x:2036.1222 y:696.022 target:1925-2175
141718:test: 2 width: 10distance: 29 time: 624 x:1646.027 y:814.01953 target:1525-1775
141719:test: 3 width: 10distance: 15 time: 688 x:504.4982 y:846.8401 target:375-375
141721:test: 4 width: 10distance: 22 time: 620 x:696.42004 y:922.6398 target:550-550
141722:test: 5 width: 10distance: 10 time: 709 x:366.33945 y:950.7717 target:250-250
141724:test: 6 width: 10distance: 7 time: 602 x:2181.1575 y:641.32117 target:2075-2325
141725:test: 7 width: 10distance: 8 time: 568 x:2207.414 y:741.3456 target:2050-2300
141726:test: 8 width: 10distance: 28 time: 490 x:1629.773 y:691.3334 target:1550-1800
141727:test: 9 width: 10distance: 23 time: 479 x:1811.6924 y:651.8706 target:1675-1925
141728:test: 10 width: 10distance: 26 time: 491 x:776.4396 y:851.138 target:650-650

As all the other data files are cvs I’ve transformed these into csv files as per Convert tab-delimited txt file into a csv file using Python. How would I go about turning the above csv files into a format where the first line is the name of each data, and the subsequent lines are the values of the data. I have about a hundred of these, so don’t want to do it manually.

  • 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-15T19:15:09+00:00Added an answer on June 15, 2026 at 7:15 pm

    This is not CSV. The format is terrible. There is no delimiter between the width and the distance fields, for example, and some fields have a space after the : colon and others don’t.

    You’ll have to process this using custom code, then write it out to a CSV file:

    import re
    import csv
    
    lineformat = re.compile(
        r'^(?P<count>\d+)[\s:]*'
        r'test[\s:]*(?P<test>\d+)[\s:]*'
        r'width[\s:]*(?P<width>\d+)[\s:]*'
        r'distance[\s:]*(?P<distance>\d+)[\s:]*'
        r'time[\s:]*(?P<time>\d+)[\s:]*'
        r'x[\s:]*(?P<x>\d+\.\d+)[\s:]*'
        r'y[\s:]*(?P<y>\d+\.\d+)[\s:]*'
        r'target[\s:]*(?P<target>\d+-\d+)[\s:]*'
    )
    fields = ('count', 'test', 'width', 'distance', 'time', 'x', 'y', 'target')
    
    with open(inputfile) as finput, open(outputfile) as foutput:
        csvout = csv.DictWriter(foutput, fields=fields)
        for line in finput:
            match = lineformat.search(line)
            if match is not None:
                csvout.writerow(match.groupdict())
    

    This uses a regular expression with named groups to parse out the line into a dictionary, for easy writing out to the CSV file. I’ve picked ‘count’ as the name for the first numeric value in your input file, feel free to change it (but do so in both the regular expression and the fields tuple).

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have been unable to fix a problem with Java Unicode and encoding. The

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.