split - 如何从excel中拆分数据集(txt文件)
问题描述
给定文本文件中的以下数据,我尝试按如下方式运行以下代码,但收到错误,例如无法将字符串转换为浮点数。看来我的字符串没有正确拆分。可能是什么问题?
def main():
with open('[filename].txt) as f:
lines = f.readlines()
for line in lines:
line = line.strip()
items = line.split()
arbor = int(items[0])
button_cav_dia = float(items[1])
shaft_dia = float(items[2])
pos_stop1 = float(items[3])
pos_stop2 = float(items[4])
pos_stop3 = float(items[5])
probing_surf_off = float(items[6])
1 14.09 12.7 4.459 4.461 4.461 1.278
2 14.09 12.7 4.458 4.472 4.474 1.281
3 14.09 12.7 4.468 4.59 4.478 1.286
4 14.09 12.7 4.463 4.71 4.471 1.278
5 14.8 12.71 4.439 4.411 4.419 1.274
6 14.09 12.71 4.398 4.457 4.47 1.277
7 14.09 12.7 4.457 4.461 4.494 1.28
8 14.08 12.71 4.464 4.475 4.466 1.283
9 14.09 12.7 4.451 4.471 4.474 1.282
10 14.09 12.71 4.411 4.416 4.423 1.265
11 14.09 12.7 4.439 4.475 4.443 1.287
12 14.09 12.71 4.476 4.466 4.506 1.289
13 14.09 12.71 4.464 4.47 4.466 1.277
14 14.08 12.71 4.477 4.461 4.444 1.282
15 14.09 12.68 4.448 4.455 4.443 1.288
解决方案
推荐阅读
- collection-select - 为什么我不能使用这个代码 f.collection_select
- returnn - 如何在更多数据上训练 LM?
- c# - 通过 C# 插入 SQL 表,代码运行良好,但我无法在数据库中找到新条目
- python - 在 1 行中进行双重 for 循环以创建新的元组列表
- linux - 是否可以在不使用 kill 命令的情况下停止 xsp --nonstop 进程?
- c - 为什么分配给直接数组时指针算术会出错
- html - 跨浏览器接受 'display:normal' css
- android - 如何使用 React Native 让 Android 设备“响铃”?
- excel - excel中的单元格颜色
- xml - 将循环内部的记录映射到不属于范围的目标记录