如何从文件中计算大于或等于某个数字的数字的百分比? [英] How can I calculate the percentage of a number greater or equal to a certain number from a file?

查看:146
本文介绍了如何从文件中计算大于或等于某个数字的数字的百分比?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用逗号分隔的CSV文件。我需要读取文件,确定哪些行包含需要高于给定数字的数字(比如711),并计算符合条件的那些数字的百分比。



我尝试过:



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



myfilecount = 0



linecount = 0



firstline = True



for myfile:

if firstline:

firstline = False
继续

fields = line.split(',')



linecount + = 1

count = int(fields [0])

color = str(fields [1])

channels = int(fields [2])

code = str(fields [3])

correct = str(fields [4])

reading = float(fields [5])



print('大于或等于711的数字百分比是%d:')

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:')

推荐答案

首先,你需要做出决定,它是C或C#或Python,但不是3,甚至不是2。

First, you need to make your mind, it is C or C# or Python, but not the 3, not even 2 of them.
Quote:

我需要读取文件,确定哪些行包含一个需要高于给定数字的数字(比如711),并计算那些数字的百分比符合条件。

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.


这篇关于如何从文件中计算大于或等于某个数字的数字的百分比?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆