read.txt用逗号这样得到数字。 1,1,1,1 \ n 2,2,2,2 \ n 3,3,3,3
我想通过程序更改每个值,我想更换新的 写入值.txt
我在很多方面做过,但我不知道如何找到逗号。
infile = open("read.txt", "r")
outfile = open("write.txt", "w")
total1 =0
count1 =0
line = infile.readline()
while line !="":
value = float(line)
total1 = total1 + value
count1 = count1 + 1
line = infile.readline()
outfile.write("Column,Sum,Mean,STD,Median,Mode,Min,Max\n")
infile.close()
outfile.close()
答案 0 :(得分:0)
首先查看python CSV模块https://docs.python.org/3.6/library/csv.html
但是对于您的原始问题,如果您正在阅读csv文件并希望获得每个"值"你想要拆分,比如
f = open("someFile.csv")
for line in f: # Loop iterates through file by grabbing text seperated by \n
listOfValuesInLine = line.split(",") #Returns a list of strings that were sepearted by ","
print(listOfValuesInLine) #Prints something like ["value1","value2","value3"] etc