简体   繁体   中英

How to formate dat file to turn into clean csv

I had a dat file of the following format

1963.00000       0.18983       0.25000
   0.24558       0.32248    1708.03226
 127.40000      34.50000     847.67600
 686.93106      16.48359       0.94900
   0.24800       0.05374       2.00000
   0.25000      74.88000       0.05300
1907.12000      67.16000       0.18446
   0.71540       0.32174    2036.00000

1964.00000       0.19803       0.25700
   0.24710       0.35442    1859.92520
 138.50000      38.40000     928.97276
 727.71924      18.04516       0.94787
   0.25400       0.05499       3.00000
   0.27000      76.96498       0.04500
2030.77821      68.44358       0.18556
   0.42009       0.34896    2139.00000

I would like to put that file in csv but not in that format but instead like that : 1963.00000 0.18983 0.25000 0.24558 0.32248 1708.03226 ... 0.71540 0.32174 2036.00000

This is for turn that dat file into clean CSV with each value of that one line become a column

file =  'Downloads/Données.dat'
lst = []
with open(path) as f :
  for line in f:
      lst += [line.split()]

i just loaded file because i'm stuck with that issue and i'm beginner in text processing.

i would like to concat each block of 8 lines into 1 lines

datfile = 'Downloads/Données.dat'
lst = []
with open(datfile) as f:
    data = f.read()
    lst += [" ".join(row) for row in [block.split() for block in data.split("\n\n")]]
for line in lst:
    print(line)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM