问题
I have a list of industries with a adjacent list of industries to categorize them. I would like to know which industries are the most common but I don't manage to make Sheets interpret two-word categories as one.
First, I would like to know which 5 categories are the most common overall. Also I would like to know the top 5 one-word (black), two-word (red) and three-word (blue) categories.
Plus, I would like to get rid of the commas.
Here's what I want to achieve and a link to a google sheets document where I've laid out all the data:
https://docs.google.com/spreadsheets/d/13N8gc4POPhFhTvyqq-UugWS5GCgcONwliacSL8-MAr8/edit#gid=0
How can these categories be grouped and listed?
回答1:
overal word:
=ARRAYFORMULA(QUERY(TRANSPOSE(SPLIT(QUERY(B3:B11&",",,99^99), ", ")),
"select Col1,count(Col1)
group by Col1
order by count(Col1) desc
limit 5
label count(Col1)''"))
overall phrase:
=ARRAYFORMULA(QUERY(TRANSPOSE(SPLIT(QUERY(B3:B11&",",,99^99), ",")),
"select Col1,count(Col1)
group by Col1
order by count(Col1) desc
limit 5
label count(Col1)''"))
one word:
=ARRAYFORMULA(QUERY(TRIM(TRANSPOSE(SPLIT(QUERY(B3:B11&",",,99^99), ","))),
"select Col1,count(Col1)
where not Col1 contains ' '
group by Col1
order by count(Col1) desc
limit 5
label count(Col1)''"))
two words:
=ARRAYFORMULA(QUERY(TRIM(TRANSPOSE(SPLIT(QUERY(B3:B11&",",,99^99), ","))),
"select Col1,count(Col1)
where Col1 matches '\w+ \w+'
group by Col1
order by count(Col1) desc
limit 5
label count(Col1)''"))
three words:
=ARRAYFORMULA(QUERY(TRIM(TRANSPOSE(SPLIT(QUERY(B3:B11&",",,99^99), ","))),
"select Col1,count(Col1)
where Col1 matches '\w+ \w+ \w+'
group by Col1
order by count(Col1) desc
limit 5
label count(Col1)''"))
回答2:
Breaking the problem into 3 formulas will allow you to support as many "words" as you want.
Step 1) put formula in D29
treat all the words as a single word (looking at your question it seems like this is the only step you really need)
=query(arrayformula(trim(substitute(transpose(split(query({substitute(B3:B," ","_")},"select * where Col1 is not null",counta(B3:B)),", ")),"_"," "))),"select Col1, count(Col1) group by Col1 order by count(Col1) desc label Col1 'Descriptions', count(Col1) 'Frequency'")
Step 2) put formula in F29
Place this next formula next to the table produced by the formula above. D30:D
should be replaced if you use different ranges.
=arrayformula({"Words";if(D30:D="","",1+LEN(D30:D)-len(SUBSTITUTE(D30:D," ","")))})
Step 3) put formula in G29
This will output the largest frequency ordered by word count D29:F
should be replaced if you use different locations
=query({D29:F},"select * where Col1 is not null order by Col3,Col2 desc")
The advantage to doing it this way is you support 1,2,3,4... word frequency.
来源:https://stackoverflow.com/questions/61066823/how-to-list-the-most-frequent-3-word-strings-on-google-sheets