我想計算從csv文件單元格中出現list_of_strings中的任何字符串的次數。有沒有辦法使用str.count()函數與值的LIST而不是單個字符串?
例如,以下工作正常。
import pandas as pd
data_path = "SurveryResponses.csv"
df = pd.read_csv(data_path)
totalCount = 0
for row in df['rowName']:
if type(row) == str:
print(row.count('word_of_interest'))
不過,我想能夠進入字符串列表([「STR1」,STR2' ,STR3' ]),而不僅僅是一個‘word_of_interest’,這樣,如果其中任何字符串出現計數值將增加1。
有沒有辦法做到這一點?
是否有任何問題的答案提供瞭解決問題了嗎? – DJK