Hi I tried the following code to count the number of rows in a csv file :
import os
os.chdir('C:\\Users')
csv_file = open("count_rows.csv", "rb")
row_count = sum(1 for row in csv_file.read())
csv_file.close()
print (row_count)
The above code displays 18 as the result when the file has only 3 rows.
Any suggestions?
Thanks so much
'rb'? That is for binary files. You just want'r'.