I am attempting to add at least one, or even multiple columns to a dataframe from a mapped dictionary. I have a dictionary keyed on product catalog numbers containing a list of standardized hierarchical nomenclature for that product number. Example below.
dict = {1: ['a', 'b', 'c', 'd'], 2: ['w', 'x', 'y', 'z']}
df = pd.DataFrame( {"product": [1, 2, 3]})
df['catagory'] = df['product'].map(dict)
print(df)
I get the following result:
    product      catagory
0        1  [a, b, c, d]
1        2  [w, x, y, z]
2        3           NaN
I would like to obtain the following:
     product     cat1     cat2     cat3     cat4
0       1          a        b       c         d
1       2          w        x       y         z
2       3         NaN      NaN     NaN       NaN
Or even better:
     product     category
0       1           d
1       2           z
2       3         NaN  
I have been trying just to parse our one of the items from the list within the dictionary and append it to the dataframe but have only found advice for mapping dictionaries that contain one item within the list, per this EXAMPLE.
Any help appreciated.
 
     
     
    