Reputation: 23
I have a csv and I need to be able to print the total number of records how is this done? I have tried using sum statements and count but nothing seems to be working
Upvotes: 1
Views: 1922
Reputation: 18
Did you use pandas to import the csv file?
If so, here are some quick and easy options for obtaining the record count:
df = pandas.read_csv(filename)
len(df)
df.shape[0]
df.index
Otherwise, an alternative solution if you used csv.reader(filename.csv)
is:
row_count = sum(1 for line in open(filename))
(this solution was originally suggested here)
Upvotes: 0
Reputation: 512
Try this:
with open(adresse,"r") as f:
reader = csv.reader(f,delimiter = ",")
data = list(reader)
row_count = len(data)
print(row_count)
Upvotes: 1