0

I have a dataset like this, and I'm looking for a way to add a category, based on what kind of product I have.

Can I search for Apple + Orange and assign them to a category named Fruits, and similar with Milk + Wine and assign them to another category, named Drinks?

| Item  | Category |
|-------|----------|
| Apple |          | <-- Fruits
| Orange|          | <-- Fruits
| Milk  |          | <-- Drinks
| Wine  |          | <-- Drinks

Or maybe a simpler method: find any rows containing Milk and assign them to category Drinks?

Filip Blaauw
  • 731
  • 2
  • 16
  • 29

3 Answers3

1

This is something you can do without code.

  • Filter or facet in the Item field for each value
  • Create a facet on the Category field
  • Click the edit button next to the blank value in the Category facet and type with the category you want to add.
  • Edit your Item facet or filter to move to the next category and repeat this process until you have categorized all yours items.
magdmartin
  • 1,712
  • 3
  • 20
  • 43
1

As magdmartin says you can do this using facets and edits - the solution he describes is probably the simplest approach and least error prone. However, if you prefer to do in a single step you can use GREL to test the content of the Item cell and then set the value in the Category cell dependent on the content of the Item cell.

with(cells["Item"].value.toLowercase(),w,if(or(w=="orange",w=="apple"),"Fruits",if(or(w=="milk",w=="wine"),"Drinks","")))

This is the same approach as given by Ettore Rizza above but in GREL rather than Jython.

Owen Stephens
  • 1,550
  • 1
  • 8
  • 10
0

magdmartin and Owen Stephens give good answers. Another simple way using GREL:

  • From the options dropdown for your 'Item' choose Edit column > Add column based on this column...
  • New column name 'Category' and in the expression set:

value.replace("Apple","Fruit").replace("Orange","Fruit").replace("Milk","Drink").replace("Wine","Drink")

You could keep adding .replace("whatever food","whatever category") ad nauseum

jmk
  • 466
  • 1
  • 4
  • 21