This is a test version of Biostars. For the public version, visit https://www.biostars.org.
filtering out some elements in matrix in python

Hi, I have a list of lists (matrix). I want to filter out those lists in my matrix with even one 0 and export the results to a .txt file.

input example:

   [['ENSG00000137288.5', '0,803921621', '0', '0,435897439', '1,384615397', '0,894736842', '1,151515086', '1,25', '1,2'], ['ENSG00000116032.5', '1,531746311', '2,67857148', '2', '3,0250002', '1,758620722', '1,571428459', '1,028571488', '1,294117703'], ['ENSG00000167578.12', '1,615720507', '2,21323528', '3,308642104', '3,934426129', '1,843137535', '0', '3,108108197', '3,33333321']]

output example which would be one of the rows in .txt file:

  ENSG00000116032.5, 1,531746311, 2,67857148, 2, 3,0250002, 1,758620722, 1,571428459, 1,028571488, 1,294117703

thanks

python

Hello behzadmoumbeini!

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

This is not strictly a bioinformatics question. Please google/ask stackoverflow.

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!

That's a pretty basic question which using google, stackoverflow or python documentation should be easy to solve. The more things you can solve on yourself, the better you become. Don't ask questions too quickly. (But don't spend too long on the same problem either.)

Just a hint: Your output format might not be parseable, because you have two sources for ',' (comma) here, and it looks like your locale is set to use , as decimal sparator. You should use a different delimiter, or just set your locale to C.

For this purpose it wouldn't really matter I guess, he is using strings not integers and could use that for counting the number of occurrences of '0'. But if he wants to do more matrix-things it would probably be preferable to use R or pandas and not nested lists...

0 answers

No answers yet.

Log in to answer this question.