How to pivot only two columns with 1 or 0 statement

I have a dataframe with the columns as follows:

Patient   Gene
1         A
1         B
2         A
2         B
2         C
3         A
3         C

And I would like to unpivot, so each patient is a row and each gene is a column, such as in

          GeneA   GeneB   GeneC
Patient1      1       1       0
Patient2      1       1       1 
Patient3      1       0       1

Hello @RoyBatty296,

use Pivoting node where grouping column will be Patient, pivoting column will be Gene and for aggregation column you need to use dummy column with value 1 (you can add it with Constant Value Column node) with aggregation First for example.

Where there’s no gene for a patient you’ll get missing values. To replace those with zero use Missing Value node.

Hope this helps!

Br,
Ivan

4 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.