This is my dataframe :
| col_1 | col_2 | col_3 | |
|---|---|---|---|
| 1 | A | abc | x |
| 2 | A | abc | y |
| 3 | A | abc | z |
| 4 | B | bcd | x |
| 5 | B | bcd | z |
| 6 | C | cde | x |
| 7 | D | def | y |
and this is what I want :
| col_1 | col_2 | col_x | col_y | col_z | |
|---|---|---|---|---|---|
| 1 | A | abc | 1 | 1 | 1 |
| 4 | B | bcd | 1 | 0 | 1 |
| 6 | C | cde | 1 | 0 | 0 |
| 7 | D | def | 0 | 1 | 0 |
I try with df.pivot but I don't known how insert 0 and 1 and how to drop unused rows at once.