Generating dataframe in python

The structure of the data file looks like this:

  2.0  0    3    9.15400
      5.40189    0.77828    0.66432
      0.44219    0.00000
  2.0  0    1    9.15400
      0.00000
  2.0  0    6    9.15400
      7.38451    3.99120    2.23459    1.49781    0.77828    0.00000
  2.0  0    3    9.15400
      2.09559    0.77828    0.00000
  2.0  0    3    9.15400
      2.09559    0.77828    0.65828
      0.58990    0.00000

and so on

I want to create a data frame that should look like this:

9.15400    5.40189    0.77828    0.44219    0.00000
9.15400    0.00000
9.15400    7.38451    3.99120    2.23459    1.49781    0.77828    0.000
9.15400    2.09559    0.77828    0.00000
9.15400    2.09559    0.77828    0.65828    0.58990    0.00000

I am finding it a bit complicated, can someone please show me how it can be solved?

If a line is indented, then append it onto the previous line.

For each line, split on whitespace, drop the first 3 items, convert the items to floats, and append the result to the output list.

Pass the output list to DataFrame.

The result will be:

       0        1        2        3        4        5    6
0  9.154  5.40189  0.77828  0.66432  0.44219  0.00000  NaN
1  9.154  0.00000      NaN      NaN      NaN      NaN  NaN
2  9.154  7.38451  3.99120  2.23459  1.49781  0.77828  0.0
3  9.154  2.09559  0.77828  0.00000      NaN      NaN  NaN
4    NaN      NaN      NaN      NaN      NaN      NaN  NaN
1 Like