I am trying to extract data from columns in a text file. One of the columns has a header which I also need to extract a whole column with repeating entries of the header, i.e:
col1 col2 col3
1 1 1
2 2 2
3 3 3
into:
col1 col2 col3 col3
1 1 1 col3
2 2 2 col3
3 3 3 col3
I am struggling isolating the header.
for line in my_file:
line = line.split("\t")
column = line[0:3] #col1-3
How do I get the header from col3 and then put it repeating? Do I have to split the line by "\n" first, then by "\t"?
I tried to do this but got an error message?