Convert dataframe to pivot table with booleans(0, 1) with Pandas

Viewed 17

I have a df looks like this

id  val1  val2

10     5     3
15     2     5
23     4     5

But need something like this

id  val1_5  val1_2  val1_4  val2_3  val2_5

10       1       0       0       1       0
15       0       1       0       0       1
23       0       0       1       0       1

How can I do this transformation with pandas?

Thanks

0 Answers
Related