Parsing a text file into a pandas DataFrame
Disclaimer: I know this is a very liberal interpretation of a code review since it suggests an entirely different approach. I still thought it might provide a useful perspective when thinking about such problems in the future and reducing coding effort.
I would suggest the following approach using regex to extract all the numbers that match the format &quot;12.34&quot;.
import re
import pandas as pd

with open(&quot;your_text_data.txt&quot;) as data_file:
    data_list = re.findall(r&quot;\d\d\.\d\d&quot;, data_file.read())

result = [data_list[i:i + 4] for i in range(0, len(data_list), 4)]

df = pd.DataFrame(result, columns=[&quot;T1&quot;, &quot;H1&quot;, &quot;T2&quot;, &quot;H2&quot;])
print(df)
df.to_excel(&quot;your_table.xlsx&quot;, index=False)

This will of course only work for the current data format you provided. The code will need to be adjusted if the format of your data changes. For example: If relevant numbers may contain a varying number of digits, you might use the regex &quot;\d+\.\d+&quot; to match all numbers that contain at least one digit on either side of the decimal point.
Also please note the use of the context manager with open(...) as x:. Only code that accesses the object needs to and should be part of the managed context.