-1

I have a data with multiple values summarized in one column like (much more rows):

"(-99.0, -99.0, -99.0, -99.0, -99.0, -99.0, -99.0, -99.0, -99.0, -99.0, -99.0, -99.0)"                                                            
"(0.43963563, 0.43963563, 0.43963563, 0.43963563, 0.43963563, 0.43963563, 0.43963563, 0.43963563, 0.43963563, 0.43963563, 0.43963563, 0.43963563)"
"(0.20000014, 0.20000014, 0.20000014, 0.20000014, 0.20000014, 0.20000014, 0.20000014, 0.20000014, 0.20000014, 0.20000014, 0.20000014, 0.20000014)"

Now my goal is to get rid of the '"', '(' and ')' and, which is the more important part, to split each row into 12 columns to finally get something like this:

      1         2            3          4          5           6             7            8          9         10           11         12
-99            -99          -99       -99         -99         -99          -99          -99         -99         -99        -99        -99
0.43963563  0.43963563  0.43963563  0.43963563  0.43963563  0.43963563  0.43963563  0.43963563  0.43963563  0.43963563  0.43963563  0.43963563
0.20000014  0.20000014  0.20000014  0.20000014  0.20000014  0.20000014  0.20000014  0.20000014  0.20000014  0.20000014  0.20000014  0.20000014

All I've got so far is some code to split my rows into separate values and to get rid of the ',':

my_file = open("expand_single_column_alternate.dat","r")
content = my_file.read()
liste = content.split(",")    
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • possible duplicate of [Python: Split string with multiple delimiters](http://stackoverflow.com/questions/4998629/python-split-string-with-multiple-delimiters) – tripleee Oct 13 '14 at 17:22
  • possible duplicate of [Python strings split with multiple delimiters](http://stackoverflow.com/questions/1059559/python-strings-split-with-multiple-delimiters) – OtherDevOpsGene Oct 13 '14 at 18:58
  • Thanks for the feedback. I'm trying to constrain my question a little bit, after I tried some things out. – Palilicium Oct 14 '14 at 10:24

1 Answers1

1

In this case, where each line is actually a valid Python tuple holding multiple numbers, you could use ast.literal_eval to turn the line into an actual tuple:

>>> import ast
>>> s = "( 1 , 2 , 3 , 4 , 5 )"
>>> ast.literal_eval(s)
(1, 2, 3, 4, 5)
tobias_k
  • 81,265
  • 12
  • 120
  • 179