I am processing a csv file and before that I am getting the row count using the below code.
total_rows=sum(1 for row in open(csv_file,"r",encoding="utf-8"))
The code has been written with the help given in this link. However, the total_rows doesn't match the actual number of rows in the csv file. I have found an alternative to do it but would like to know why is this not working correctly??
In the CSV file, there are cells with huge text and I have to use the encoding to avoid errors reading the csv file.
Any help is appreciated!
pandas.read_csvwill read it correctly as opposed toopenwhich reads the file line by line, not considering the huge text as one.opendoesn't know it should be considered as one cell, and simply returns count of lines.\rand\nthat might give your a wrong count? or some\nor\rwithin some cell text?python count_row.py 1715181568same result withwc -l