Skip to content
Advertisement

Reading software-specific text file data into pandas dataframe

A software I use outputs the results as text txt files in the following way Output Text File.

or like here for example:

JavaScript

Now I want to analyse the results for each joint and dont know how to import the text file into pandas in a feasible way. Optimally I want something like this Wanted Format or a separate pandas dataframe or numpy array / list for each joint. Like here for example:

JavaScript

Would be great if someone can help with how to deal with the hyphen line breaks of the output text file.

Advertisement

Answer

With a slightly modified Output Text File

JavaScript

pasted into a file named output.txt this

JavaScript

produces the following output (print(df))

JavaScript

at least for me. (This stuff is a bit fickle, the exact formatting of the file is rather important.) The list dfs contains one DataFrames for each “joint”, if you rather want to deal with them individually.

If you are more interested in a vertical arrangement with Time as part of the index then the replacement

JavaScript

produces

JavaScript

The difference in the file is that Parameter 2 is replaced with Parameter2. So the question is: Is whitespace in the header names possible? If so, things get more complicated.

Taking up your idea in the comment this should also work:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement