I have a frame like this
presence_data = pd.DataFrame({
"id": ["id1", "id2"],
"presence": [
["A", "B", "C", "A"],
["G", "A", "B", "I", "B"],
]
})
| id | presence |
|---|---|
| id1 | [A, B, C, A] |
| id2 | [G, A, B, I, B] |
I want to transform above into something like this...
| id | A | B | C | G | I |
|---|---|---|---|---|---|
| id1 | 2 | 1 | 1 | 0 | 0 |
| id2 | 1 | 2 | 0 | 1 | 1 |
Currently, I have a approach where I iterate over rows and iterate over values in presence column and then create/update new columns with count based on the values encountered. I want to see if there is a better way.