我需要知道字符串在CSV文件中出現的次數。我擁有的代碼並沒有給我正確的編號。如何查找字符串在CSV文件中出現的次數
import csv
import re
def main():
print('Here is the File Information.')
print('_' * 29)
infile = open('employee_payroll.csv', 'r').read()
count = 0
string = 'Board of Regents'
for string in infile:
count+= 1
請更多的細節描述... **「不給我正確的號碼」 ** ...你遠離正確的? –
''Board of Regents''實際上並沒有在任何地方使用,因爲'string'的名字立即被循環變量取代;你實際上只是計算文件中的行數。另外請注意,Python有一個'csv'庫,可能會幫助你。 – jonrsharpe