I have a presence/absence dataframe that looks like this (it's much larger but have reduced it for this question):
annotations factor1 factor2 factor3 Class
heroine 1 0 1 OPIOID_TYPE
he smokes 0 1 0 OTHER_DRUG_USE
heroin 1 0 1 OPIOID_TYPE
What I would like to do is create a new dataframe for each unique value in 'Class' and insert each value in class as the name of the last column for each dataframe and record presence/absence.
In other words:
annotations factor1 factor2 factor3 OPIOID_TYPE
heroine 1 0 1 1
he smokes 0 1 0 0
heroin 1 0 1 1
and:
annotations factor1 factor2 factor3 OTHER_DRUG_USE
heroine 1 0 1 0
he smokes 0 1 0 1
heroin 1 0 1 0
In reality, my dataframe is much larger with 2289 rows and 1273 columns and exactly 23 unique values in 'Class' for a total of 23 new dataframes.
I assume a loop structure would work here but I have limited experience with python looping.