import csv
oneFileName = listOfFiles[0]
lineNum = 0
listOfLists = []
with open(oneFileName,"rt") as csvfile:
lineReader = csv.reader(csvfile,delimiter=",",quotechar="\"")
for row in lineReader:
lineNum = (lineNum + 1)
if lineNum == 1:
print("Skipping the header row")
continue
symbol = row[0]
close = row[5]
prevClose = row[7]
tradedQty = row[9]
pctChange = float(float(close)/float(prevClose) - 1)
oneResultRow = [symbol, pctChange,float(tradedQty)]
listOfLists.append(oneResultRow)
print(symbol, "{:,.lf}".format(float(tradedQty/1e6), "M INR", "{:,.lf}".format(pctChange*100), "%"))
print("Done iterating over the file contents - the file is closed now!")
print("We have stock info for " + str(len(listOfLists)))
listOfListsSortedByQty = sorted(listOfLists, key=lambda x:x[2], reverse=True)
listOfListsSortedByQty = sorted(listOfLists, key=lambda x: x[1], reverse=True)
我一直收到此错误:
print(symbol, "{:,.lf}".format(float(tradedQty/1e6), "M INR", "{:,.lf}".format(pctChange*100), "%"))
TypeError: unsupported operand type(s) for /: 'str' and 'float
答案 0 :(得分:1)
不,问题是你把括号放在错误的地方。
float(tradedQty)/1e6
我确定你打算写:
HazelcastInstance testInstance = Hazelcast.newHazelcastInstance(config);
答案 1 :(得分:0)
tradedQty
是一个字符串。 1e6
是数字,不是问题。
CSV文件只是字符串,因此您希望将数字数据转换为数字类型。试试tradedQty = float(row[9])