python将输出结果写入csv_Python:在多行中将循环结果写入csv

1586010002-jmsa.png

Hi everyone!

I want to write a list of 2500 numbers into csv file.

From the code below, I only manage to get the list written in one row with 2500 columns in total. My expectation is to have 25 columns, where after every 25 numbers, it will begin to write into the next row.

Expected:

0.81 0.87 0.17 0.31......... 0.76(25th)

0.31.........................0.10(50th)

What I have tried:csv_output = csv.writer(open("c.csv", "wb"))

csv_output.writerow(["Col1","Col2","Col3","Col4","Col5","Col6","Col7","Col8","Col9","Col10","Col11","Col12","Col13","Col14","Col15","Col16","Col17","Col18","Col19","Col20","Col21","Col22","Col23","Col24","Col25"])

i=0

for row in csv_f2:

print ("Superpixel features",row)

a = float(row[0])

for row2 in csv_f1:

b = float(row2[i])

c = (b-a)

print ("%.8f, %.8f, %.8f" % (a, b, c))

# save the feature vector using CSV

outputf = ([c])

outf.append(outputf)

csv_output.writerow(outf)

f1.seek(0)

i=i+1

解决方案Quote:From the code below, I only manage to get the list written in one row with 2500 columns in total. My expectation is to have 25 columns, where after every 25 numbers, it will begin to write into the next row.

You need to count the numbers you outputs, and every time you reach 25, add a newline to output.

Is it a problem for you ?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值