Skip to content
Advertisement

summing the values row wise

I have a three column of data as arranged below:

Input file:

JavaScript

In the above input file the first column values are repeated so I want to take only once that value and want to sum the third column values row wise and do not want to take any second column values.

I also want to append a third column with the fixed value 1.0

Finally want to save the result on another test file called output.txt.

Output:

JavaScript

In the output second column values resulted from is following:

JavaScript

I tried with numpy but getting error:

JavaScript

Advertisement

Answer

You need to read your input file using pandas.read_csv, you need to set the delimiter to " ", specify no header and ">" as comment lines.

Then perform the groupby/sum operation, and export without header using pandas.to_csv

JavaScript

output.txt:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement