This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Looping over a section of data and suming in python

I have a fairly large dataset, I would like to read data from a file and sum values equal to 1 for every row and write it to a file. My code just prints data back to me

Example input file:

1526  0 1 2 1 0

782   0 1 1 1 2

7653  1 1 1 0 0

87bt  1 0 1 2 2

Example desired output file:

1526 2

782 3

7653 3

87bt 2

my code:

df = pd.read_csv("data1", header=None, index_col=0) 

df.eq(1).sum(axis=1)
python pandas numpy

Hello elhamidihay!

We believe that this post does not fit the main topic of this site.

This is not a bioinformatics question in its current form. Please tell us how this is related to bioinformatics.

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

Hello,

Thank you for your feedback. I have a data set of genotypes and I'm trying compute the heterozygosity for each individual. I'm using python to perform the task.

Thank you.

0 answers

No answers yet.

Log in to answer this question.