我有一个包含数字整数和浮点数的 csv 文件,
"5",7.30124705657363,2,12,7.45176205440562
"18",6.83169608190656,5,11,7.18118108407457
"20",6.40446470770985,4,10,6.70549470337383
"3",5.37498781178147,17,9,5.9902122724706
"10",5.12954203598201,8,8,5.58108702947798
"9",3.93496153596789,7,7,4.35751055597501
我正在做一些算术,然后我试图将它们添加到字典中,但我遇到了关键错误。这是我的代码,
global oldPriceCompRankDict
oldPriceCompRankDict = {}
def increaseQuantityByOne(self, fileLocation):
rows = csv.reader(open(fileLocation))
rows.next()
print "PricePercentage\t" + "OldQuantity\t" + "newQuantity\t" + "oldCompScore\t" + "newCompScore"
for row in rows:
newQuantity = float(row[2]) + 1.0
newCompetitiveScore = float(row[1]) + float(math.log(float(newQuantity), 100))
print row[1] + "\t", str(row[2])+"\t", str(newQuantity) + "\t", str(row[4]) + "\t", newCompetitiveScore
oldPriceCompRankDict[row[3]].append(row[4])
我有未排序的密钥,我认为密钥不必采用有序格式。我认为任何事情都可能是关键。