I'm fairly new to Pandas and am really stumped on a project.
I have a Pandas dataframe that looks like this:
| ID | Retailers |
|---|---|
| ID_1 | ["retailer 1", "retailer 2", "retailer 3"] |
| ID_2 | ["retailer 1", "retailer 2"] |
My goal is:
- Loop through a list of all possible retailers.
- Create a column for each possible retailer
- If the current retailer is in the row's list of retailers, then they should be coded as a 1
- If that retailer is not in the list, then they should be coded as a 0
Using retailer 3 as an example:
| ID | Retailers | retailer 3 |
|---|---|---|
| ID_1 | ["retailer 1", "retailer 2", "retailer 3"] | 1 |
| ID_2 | ["retailer 1", "retailer 2"] | 0 |
Hope that makes sense.


