python获取csv某一列最小值,查找从CSV文件Python生成的列表的最小值和最大值

该博客介绍如何使用Python从CSV文件中读取数据,并计算每行数据的最小值和最大值。通过示例代码展示了如何处理CSV文件,计算平均值并按特定列排序,最后将结果打印出来。示例包括使用列表推导式和内置函数`min`和`max`来找到每行的最小和最大数值。
摘要由CSDN通过智能技术生成

I am trying to find the MIN and MAX values for each row of a CSV file and append them to the next position in the list, positions 5 and 6. I have managed to calculate the average, append this to the forth position and output this in highest to lowest however, I am struggling to work out how to find the MAX and MIN values of each row so I can do the same - highest to lowest. The original CSV is formatted: Fred,56,78,99 with each user on a new line.

Any help would be appreciate.

import csv

import operator

sample = open("sampleData.txt", "r")

csv1 = csv.reader(sample, delimiter = ',')

sort = sorted(csv1,key=operator.itemgetter(0))

for i in range( 0, len(sort)):

sort[i].append((int(sort[i][1]) + int(sort[i][2]) + int(sort[i][3])) / int(len(sort[i])-1))

sort = list(reversed(so

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值