Read a multiple data typed .dat file into a python array

  numpy, pandas, python

Looking to get a faster way to parse the following .dat file, into a list or a numpy array.
Tried multiple configurations of np.genfromtxt(), np.loadtxt(), also just a csv.reader(), from a csv module.

The issue/ challenge being – One, the delimiter is "," in first four lines and " " (space) after that. Second, the data is also a combination of strings/ floats. I am mainly looking to read the 3rd line (I, J values), and the data from 5th line to an array.

TITLE = "B0001"
VARIABLES = "x [mm]", "y [mm]", "Intensity [counts]", "isValid"
ZONE T="Frame 0", I=1930, J=1798, F=POINT
STRANDID=1, SOLUTIONTIME=0.100904755
-123.047997 130.550003 0 0
-122.915267 130.550003 0 0
-122.782537 130.550003 0 0
-122.649806 130.550003 0 0
-122.517076 130.550003 0 0
-122.384346 130.550003 0 0

Source: Python Questions

LEAVE A COMMENT