swn.file.read_formatted_frame#

swn.file.read_formatted_frame(fname)#

Read a free formatted table to data frame.

Parameters:
fnamePath, str or file-like object

Path to read file.

Returns:
pandas.DataFrame

Notes

First line must be a header, which may start with ‘#’.

Examples

>>> from io import StringIO
>>> import pandas as pd
>>> from swn.file import read_formatted_frame
>>> f = StringIO('''\
... # ifno        value1  value2  value3
... 1      -1.000000e+10       1  'first one'
... 12     -1.000000e-10      10   two
... 33      0.000000e+00     100   three
... 40      1.000000e-10    1000
... 450     1.000000e+00   10000   five
... 6267    1.000000e+03  100000   six
... ''')
>>> df = read_formatted_frame(f).set_index("ifno")
>>> print(df)
            value1  value2     value3
ifno
1    -1.000000e+10       1  first one
12   -1.000000e-10      10        two
33    0.000000e+00     100      three
40    1.000000e-10    1000       None
450   1.000000e+00   10000       five
6267  1.000000e+03  100000        six