java csv 数组,将不同长度的数组列表保存到csv

我有 data_pressure ,这是一个numpy数组的列表,例如:

array([ 268752., 26222., 261152., 260958.]),

array([ 123433., 98239., 98932.]),

array([ 2893789., 872398., 92839., 9283982., 7632762., 547627.,])

每个阵列都有不同的长度 .

我用Python的csv模块保存到这个数组列表:

import csv

csvfile = "csvfile.csv"

with open(csvfile, "w") as output:

writer = csv.writer(output, lineterminator='\n')

for line in data_pressure:

writer.writerow(line)

一切都像魅力一样,但正如我所读到的那样

import csv

data = []

with open('csvfile.csv', 'rb') as csvfile:

spamreader = csv.reader(csvfile)

for row in spamreader:

data.append(np.asarray(row))

我明白了

array([ '268752.0', '26222.0', '261152.0', '260958.0']),

array([ '123433.0', '98239.0', '98932.0']),

array([ '2893789.0', '872398.0', '92839.0', '9283982.0', '7632762.0', '547627.0',])

然后,任何数组中的每个值都是字符串类型而不是浮点数 .

有没有办法规避这个问题?

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值