Skip to content
Advertisement

Pandas dataframe manipulation/re-sizing of a single-column count file

I have a file that looks like this:

JavaScript

I want to read this into a pandas dataframe and re-shape it so that it looks like this:

JavaScript

Is this possible? If so, how?

Notes: it will not always be this size, so the solution needs to be size-independent. The input file will be max ~200gRNAs x 20genes. There will be gRNA_somelettercombos, but the gene will not be named gene_lettercombo– the gene will be the name of an actual gene (like GAPDH, ACTB, etc.).

Advertisement

Answer

You need to write a parser for your custom format, relying on the gRNA string to start a new group and then taking odd elements as key and even as value:

JavaScript

output:

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