以下是使用python的内置包实现此目的的方法:import csv
from collections import OrderedDict
newdata = OrderedDict()
with open('test.csv', 'rb') as testr:
testreader = csv.reader(testr)
for row in testreader:
name = row[0]+ '-' + row[1]
if name in newdata:
newdata[name] = [max(existdata, readdata) for existdata, readdata in zip(newdata[name], row[2:])]
else:
newdata[name] = row[2:]
with open('newdata.csv', 'wb') as testw:
testwriter = csv.writer(testw)
for name, data in newdata.iteritems():
testwriter.writerow(name.split('-') + data)
最好的办法就是用熊猫做,一会儿就会发帖。在
编辑:
以下是熊猫守则:
^{pr2}$
max_readfile = readfile.groupby(['FirstName', 'LastName']).max()
print max_readfile
输出:
***@user2241910很快发布了熊猫解决方案:)