Why is python giving the count of fields in all of the rows in a csv file the same as the row with the max count? -


i have csv file each row containing review , each sentence of review in separate column--so each row not have same number of columns. wrote python code print out total number of reviews , sentences, , max, min, , avg number of sentences per review. worked on small sample (5 rows). however, when tried larger csv file (10,000 rows) had copied sample from, max, min , avg came out 18. i'm thinking maybe file giving of rows same number of columns (sentences) largest row has. if that's case, there way fix this?

here code in case i've made mistake in it:

import csv  open('reviews.csv', 'rt') f:     reader = csv.reader(f)     num_sentences = []     row in reader:         num_sentences.append(len(row))  print("total reviews:", len(num_sentences)) print("total sentences:", sum(num_sentences))    print("max sentences per review:", max(num_sentences)) print("min sentences per review:", min(num_sentences)) print("average sentences per review:", (sum(num_sentences)/(len(num_sentences))) 

here file using:

i had 2 classes , awful.,terrible teaching skills ,     have no idea doing.,she'd curve tests make poor quality.,"as person, pretty nice teaching skills lacking." can't believe retards woman had deal - she's freakin' saint having put of ****.,professor green funny , easy understand - awesome professor! easy a. boring class.,find friend in class can keep each other awake.,"the class boring, painful sit through.","however, did me make dean's list, since it's impossible not a." class extremely boring , waste of time.,she not seem care students. no comments 

here printout file:

total reviews: 5 total sentences: 13 max sentences per review: 4 min sentences per review: 1 average sentences per review: 2.6    


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -