Engine
Engine

Reputation: 5422

CSV in python getting wrong number of rows

I have a csv file that I want to work with using python. For that I'm run this code :

import csv
import collections

col_values = collections.defaultdict(list)
with open('list.csv', 'rU',) as f:
    reader = csv.reader(f)
    data = list(reader)
    row_count =len(data)
    print(" Number of rows  ", row_count)

As a result I get 4357 but the file has only 2432 rows, I've tried to change the delimiter in the reader() function, it didn't change the result. So my question is, does anybody has an explanation why do I get this value ? thanks in advance

UPDATE

since the number of column is also too big , here is the output of the last row and the start of non existing rows for one columns enter image description here

opening the file with excel the end looks like :

enter image description here

I hope it helps

Upvotes: 0

Views: 1132

Answers (1)

Shubham R
Shubham R

Reputation: 7644

try using pandas.

import pandas as pd
df = pd.read_csv('list.csv')
df.count()

check whether you are getting proper rows now

Upvotes: 1

Related Questions