1

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

1
  • please provide your code snippets, just asking question won't help. Commented Mar 21, 2018 at 3:51

2 Answers 2

1

Try this:

with open(adresse,"r") as f:
    reader = csv.reader(f,delimiter = ",")
    data = list(reader)
    row_count = len(data)
print(row_count)
Sign up to request clarification or add additional context in comments.

Comments

0

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)

1 Comment

thanks fam this one worked..such a simple code I feel silly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.