I have been having troubles with extracting reading/manipulating/extracting data from a txt file. In the text file it has a general header with various information that is setup something like this below just as an example:

```
~ECOLOGY
~LOCATION      
LAT:           59  
LONG:          23

~PARAMETERS
Area.          8
Distribution.  3
Diversity.     5

~DATA  X        Y        CONF     DECID    PEREN
       3        6        1        3        0       
       7        2        4        2        1
       4        8        0        6        2
       9        9        6        2        0
       2        3        2        5        4  
       6        5        0        2        7 
       7        1        2        4        2

```

I want to be able to extract the headers of the columns and use the headers of the columns as an index or key since sometimes the types of column data can change between files and the amount of rows of data can fluctuate as well. I want to be able to read the data in each column so that pending on location I can sum or add columns such as show below and export it as a separate file:

```
~DATA  X        Y        CONF     DECID    PEREN    TOTAL 
       3        6        1        3        0        4       
       7        2        4        2        1        7
       4        8        0        6        2        8 
       9        9        6        2        0        8 
       2        3        2        5        4        11
       6        5        0        2        7        9
       7        1        2        4        2        8

```

Any suggestions?

This is what I have so far:

```
E = open("ECOLOGY.txt", "r")
with open(path) as E:
    for i, line in enumerate(E):
        sep_lines = line.rsplit()
        if "~DATA" in sep_lines:
            key =(line.rsplit())
            key.remove('~DATA')
            for j, value in enumerate(key):
                print (j,value)
            print (key)
            dict = {L: v for v, L in enumerate(key)}
            print(dict)  

```