-3

I have data in a file that looks like this:

screenshot of the file

As you can see the data is very neat, but it is not separated in a concise fashion, but rather a variable number of spaces between columns and some columns left blank. This makes it import incorrectly into, for example, Excel. I have tried import functions in spyder and sage. I did not create the file.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
user2132672
  • 67
  • 2
  • 9

2 Answers2

0

try import it and see what you get.

media = []
with open("filename.dat", "r") as f:
    media.append(f.readlines())
for row in media:
    do something with row

on 2nd thought it looks like it may be tab-delimited:

import csv
with open("filename.dat", "rB") as f:
    csv_file = csv.reader(f, deilmiter='\t')
for row in csv_file:
    do something with row
Daniel Lee
  • 7,189
  • 2
  • 26
  • 44
0

This is a fixed width file, so using pandas with python is the way to go:

http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_fwf.html

user2132672
  • 67
  • 2
  • 9