0
假設我有幾個文檔和一個df列,其中包含我需要搜索的特定單詞,那麼如何計算單詞在文檔中出現的次數?基於熊貓中的列和字符串進行計數
一個例子更好。
例子:
doc1 = "I am a cat that barks. I like dog food instead of cat food. Roff"
doc2 = "Frog that barks. Frog like cats."
df['words'] = ["dog","cat","frog"]
尋找它變成一個DF,將這個樣子。
它看起來像這樣,但我意識到它只是循環到同一個單元格。所以我總是變得零。
for i in range(len(doc)):
for key, value in doc.items():
for word in df['word']:
df['doc_' + str(i)] = value.count(word)