所以我有一个csv(https://ufile.io/y4nr9),用''分隔,包含了诸如'name'、'survive'、'sex'等列。我想找出没有存活下来的男性的百分比并打印统计数据。以下是我目前为止的代码:
import csv
reader = csv.reader(open('titanic-new_alphabetized.csv'), delimiter= ',')
filtered = filter(lambda p: 'male' == p[3], reader)
dict = []
input('press ENTER to exit')
还应该将文件作为变量打开,以便以后可以轻松地关闭它。在
或使用
with ... as
打开文件。在您正在使用
list
语法创建词典。在您应该使用dict={}
在Python3中,您可以过滤它们并计算统计信息:
输出:
^{pr2}$相关问题 更多 >
编程相关推荐