我需要知道字符串在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