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
            Asked
            
        
        
            Active
            
        
            Viewed 1,764 times
        
    1
            
            
        - 
                    please provide your code snippets, just asking question won't help. – Nothing Mar 21 '18 at 03:51
2 Answers
1
            
            
        Try this:
with open(adresse,"r") as f:
    reader = csv.reader(f,delimiter = ",")
    data = list(reader)
    row_count = len(data)
print(row_count)
 
    
    
        Nothing
        
- 502
- 3
- 11
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)
 
    
    
        adono
        
- 18
- 6
 
    