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
2 Answers
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
rohan
thanks fam this one worked..such a simple code I feel silly