1

I have a dataframe of this format:

df= {
'name': ['X', 'X', 'X']
'id':  ['1', '1', '2', '2', '3', '3'],
'group': ['A', 'B', 'A', 'A', 'C', 'A']
}

(there are a few thousand rows, and actually 7 unique groups)

I want to present this as a table of some sort along the lines of

id | A | B | C 
1 | 1 | 1 | 0
2 | 2 | 0 | 0
3 | 1 | 0 | 1

But I'm having trouble with manipulating the data. I have tried using value counts, which sort of works, but I'd like to aggregate these results (carrying out the same check on many data frames), and value_counts() doesn't include groups with a value of 0, because it wouldn't know that it exists.

Thanks in advance

0 Answers0