Click here to Skip to main content
14,207,483 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
I have a CSV file separated by commas. I need to read the file, determine which lines contain a number that needs to be higher than a given number (say 711), and calculate the percentage of those numbers that fit the criteria.

What I have tried:

myfile = open('3517315a.csv','r')

myfilecount = 0

linecount = 0

firstline = True

for line in myfile:
if firstline:
firstline = False
continue
fields = line.split(',')

linecount += 1
count = int(fields[0])
colour = str(fields[1])
channels = int(fields[2])
code = str(fields[3])
correct = str(fields[4])
reading = float(fields[5])

print( 'percentage of numbers greater than or equal to 711 is %d:')
Posted
Updated 23-Mar-17 9:06am
Comments
NotPolitcallyCorrect 23-Mar-17 15:06pm
   
Other than reposting this same thing over and over, what have you tried? Isn't calculating percentages like 4th grade math?

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

First, you need to make your mind, it is C or C# or Python, but not the 3, not even 2 of them.
Quote:
I need to read the file, determine which lines contain a number that needs to be higher than a given number (say 711), and calculate the percentage of those numbers that fit the criteria.

If you read the file on screen, how do you do to count the number of values that meet the criteria and what you need to get the percentage of values that meet the criteria ? The program will do the same.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190612.1 | Last Updated 23 Mar 2017
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100