0

I had a column in a dataframe with list entries. I wanted to create separate 1/0 columns based on the values in the list.

Input DF:

| Contract|  list             |
|---------|-------------------|
|  1      | [16a1,16a2,17b1]  |
|  2      | []                |
|  3      | [16a1,7b1]        |

Expected output:

| Contract|  list             | 16a1 | 16a2| 17b1| 7b1 |
|---------|-------------------|------|-----|-----|-----|
|  1      | [16a1,16a2,17b1]  |  1   |  1  |  1  |  0  |
|  2      | []                |  0   |  0  |  0  |  0  |
|  3      | [16a1,7b1]        |  1   |  0  |  0  |  1  |

I don't have any idea as to how to proceed.

I tried using numpy where condition to search for specific key words and create column but not of much help

James Z
  • 12,209
  • 10
  • 24
  • 44

0 Answers0