I am still struggling with the after effects of Linux reinstallation on my system.
Two major problems:
1) Firefox and openoffice is still not in English. Its giving me hard time.
2) The functions in openoffice version of excel is not working.
I am yet to sort that out. In the mean time, I desperately needed it to do simple task. subtracting values of one column from one in another column and write the difference in next column.
So, I had input in this form:
------------------
0 2.179139 0.951816
1 2.314531 1.006480
2 2.191692 0.951938
3 2.079704 0.952747
4 2.092761 0.939545
5 2.362056 0.984791
6 2.153595 0.957934
7 2.213173 0.951768
8 2.175687 0.953091
--------------------
I needed to subtract column 3 data from column 2 data. So, I tried this:
---------------------------
#!/usr/bin/env python
fo=open('name.txt' +'_output','w')
with open('name.txt') as fd:
for line in fd:
columns=line.split()
columns=map(float,columns)
fo.write ("%s \t %s \n" %(line.strip(), columns[1] - columns[2]))
-----------------------------
It creates an output with difference written in next column :
---------------------------------
0 2.179139 0.951816 1.227323
1 2.314531 1.006480 1.308051
2 2.191692 0.951938 1.239754
3 2.079704 0.952747 1.126957
4 2.092761 0.939545 1.153216
5 2.362056 0.984791 1.377265
6 2.153595 0.957934 1.195661
7 2.213173 0.951768 1.261405
8 2.175687 0.953091 1.222596
---------------------------------
It works fine, only problem is it ends with an error:
IndexError: list index out of range
Although it doesn't effect the result.
So, for the moment I got the result I wanted but I will come back and take care of this small issue.
Two major problems:
1) Firefox and openoffice is still not in English. Its giving me hard time.
2) The functions in openoffice version of excel is not working.
I am yet to sort that out. In the mean time, I desperately needed it to do simple task. subtracting values of one column from one in another column and write the difference in next column.
So, I had input in this form:
------------------
0 2.179139 0.951816
1 2.314531 1.006480
2 2.191692 0.951938
3 2.079704 0.952747
4 2.092761 0.939545
5 2.362056 0.984791
6 2.153595 0.957934
7 2.213173 0.951768
8 2.175687 0.953091
--------------------
I needed to subtract column 3 data from column 2 data. So, I tried this:
---------------------------
#!/usr/bin/env python
fo=open('name.txt' +'_output','w')
with open('name.txt') as fd:
for line in fd:
columns=line.split()
columns=map(float,columns)
fo.write ("%s \t %s \n" %(line.strip(), columns[1] - columns[2]))
-----------------------------
It creates an output with difference written in next column :
---------------------------------
0 2.179139 0.951816 1.227323
1 2.314531 1.006480 1.308051
2 2.191692 0.951938 1.239754
3 2.079704 0.952747 1.126957
4 2.092761 0.939545 1.153216
5 2.362056 0.984791 1.377265
6 2.153595 0.957934 1.195661
7 2.213173 0.951768 1.261405
8 2.175687 0.953091 1.222596
---------------------------------
It works fine, only problem is it ends with an error:
IndexError: list index out of range
Although it doesn't effect the result.
So, for the moment I got the result I wanted but I will come back and take care of this small issue.
Comments
Post a Comment