如何計算一個單詞在一列中的字符串出現在Python中的次數?例如:如何計算單詞在一列中出現的次數,python
file|context
----|-------
1 | Hello world
2 | Round and round
我想計算的話發生:
file| context | word_count
----|-----------------|---------------------
1 | Hello world | {'hello':1,'world':1}
2 | Round and round | {'round':2,'and':1}
我一直停留在它了整整一天,並試圖用value_counts()和計數器。仍然無法弄清楚。任何幫助?
謝謝!
你是如何嘗試使用Counter和value_counts()? –
你正在展示什麼樣的數據結構?如果您正在討論解析文本表而不是像pandas'數據框這樣的工作,你會得到非常不同的答案。可能會添加適當的標籤('string'和'count'在這裏非常無用)。 – Blckknght