I have a large dataframe that includes a description of the goods (about 11000 rows). I want to extract new variables (product type and product color) from the Goods.Description.
id Goods.Description Jeans T.Shirt Skirt Top Color
1 1 This green T-shirt can become... 0 0 0 0 0
2 2 Stripes of unfaded denim at each side of this blue skirt make... 0 0 0 0 0
3 3 Velvet's Brynna red top comes in a bohemian... 0 0 0 0 0
4 4 The Riley blue jeans are Paige's take on... 0 0 0 0 0
For example, If Goods.Description contains the word "T-shirt", then put 1 in T.Shirt, else 0.
If Goods.Description contains the word "jeans", then put 1 in Jeans, else 0.
If Goods.Description contains the word "skirt", then put 1 in Skirt, else 0.
If Goods.Description contains the word "top", then put 1 in Top, else 0.
If Goods.Description contains the word "green", then put green in Color, else 0.
If Goods.Description contains the word "blue", then put blue in Color, else 0.
and so on
After:
id Goods.Description Jeans T.Shirt Skirt Top Color
1 1 This green T-shirt can become... 0 1 0 0 green
2 2 Stripes of unfaded denim at each side of this blue skirt make... 0 0 1 0 blue
3 3 Velvet's Brynna red top comes in a bohemian... 0 0 0 1 red
4 4 The Riley blue jeans are Paige's take on... 1 0 0 0 blue
I do not know what the code should be. Please, help me.
Aucun commentaire:
Enregistrer un commentaire