I have a dataframe column which is a an enumerated list of items and I'm trying to split them into multiple columns. for example
dataframe column that looks like this:
ID | ITEMS |
---|---|
ID_1 | 1. Fruit 12 oranges 2. vegetables 7 carrot 3. NFL 246 SHIRTS |
ID_2 | 1. Rock 2000 tons 2. PAPER 7 Notebook 3. Scissors 246 pairs |
the preferred result is something like this:
ID | Fruit | vegetables | NFL | Rock | PAPER | Scissors |
---|---|---|---|---|---|---|
ID_1 | 12 oranges | 7 carrot | 0 | 0 | 0 | 0 |
ID_2 | 0 | 0 | 246 SHIRTS | 2000 tons | 7 Notebook | 246 pairs |
Also the number of the items varies from row to another [2-7] I'm trying to use str.extract
df['ITEMS'].str.extract('(\d\.+)', flags=re.M, expand=True)
but it didn't work