import text to pandas with multiple delimiters

One way might be to use the regex separators permitted by the python engine. For example:

>>> !cat castle.dat
c stuff
c more header
c begin data         
 1 1:.5
 1 2:6.5
 1 3:5.3
>>> df = pd.read_csv('castle.dat', skiprows=3, names=['a', 'b', 'c'], 
                     sep=' |:', engine="python")
>>> df
   a  b    c
0  1  1  0.5
1  1  2  6.5
2  1  3  5.3

Leave a Comment