I want to add a new column in an existing file and would like to write the output to another file. I open the file as follows and add my required statements. How do I write my output to the file by adding a new column at the end( With column name/Header). The separation is tab.
with open(newfile, 'w') as outfile:
with open(oldfile, 'r', encoding='utf-8') as infile:
statements:
sample of input:
Col1 Col2 Col3 Col4
Val1 Val1 Val1 Val1
Val2 Val2 Val2 Val2
Val3 Val3 Val3 Val3
Val4 Val4 Val4 Val4
sample of output:
Col1 Col2 Col3 Col4 Col5(Newly added)
Val1 Val1 Val1 Val1 Val1
Val2 Val2 Val2 Val2 Val2
Val3 Val3 Val3 Val3 Val3
Val4 Val4 Val4 Val4 Val4
Thanks in advance.