python读取txt指定内容写入数组,如何使用Python将文本文件中的数据读取到数组中...

使用Python进行回归分析时,遇到如何从txt文件中读取特定格式的数据(如2104,3,399900)并存储到数组中的问题。提出了两种存储方式:分别存储每列数据或合并存储。提供了代码示例,通过`with open()`读取文件,然后使用`split()`和`map(int, substring.split(','))`将数据转换为整数列表。最终给出了计算平均值的代码片段,并给出了具体输出结果。" 117006924,10295764,使用MegaCli修复Linux RAID0阵列,"['RAID技术', 'Linux系统管理', '存储设备', '故障排查']
摘要由CSDN通过智能技术生成

I have a bit trouble with some data stored in a text file on hand for regression analysis using Python.

The data are stored in the format that look like this:

2104,3,399900 1600,3,329900 2400,3,369000 ....

I need to do some analysis like finding mean by this:

(2104+1600+...)/number of data

I think the appropriate steps is to store the data into array. But I have no idea how to store it. I think of two ways to do so. The first one is to set 3 array that stores like

a=[2104 1600 2400 ...] b=[3 3 3 ...] c=[399900 329900 36000 ...]

The second way is to store in

a=[2104 3 399900], b=[1600 3 329900] and so on.

Which one is better?

Also, how to write code that allows the data can be stored into array? I think of like this:

with open("file.txt", "r") as ins:

array

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值