I am trying to open a .txt file in Python.
Before flagging this of as repeat, please do take a look at the code and the file below.
I have used this snippet to read similar files before, however this particular batch of files does not work.
location="sample/sample2/"
filename=location+"Detector_-3000um.txt"
skip=25 #Skip the first 25 lines
The code to open it is -
f=open(filename)
num_lines = sum(1 for line in f)
print "Skipping the first "+str(skip)+" lines"
data=np.zeros((num_lines-skip+1,num_lines-skip+1))
f.close()
f=open(filename)
i=0
for _ in range(skip): #skip unwanted rows
next(f)
for line in f:
data[i,:]=line.split()
i+=1
f.close()
Its a 501x501 data set with the first row and column being the row and column numbers resp.
The data set is attached here.
I also tried using panda - pd.read_csv(filename,skiprows) however it gives this error -
CParserError: Error tokenizing data. C error: Expected 1 fields in line 49, saw 501