python - 将两列中的数据保存到两个列表中
问题描述
我有两列浮点数。我需要将每列中的数据分成单独的列表(x 和 y)并绘制数据 y 与 x。我写了一些东西,但它一直给我一个错误,即 ValueError: need more than 1 value to unpack
数据文件的提取如下所示,
0.0 1.0
0.02 1.0
0.04 1.0
0.06 1.0
0.08 1.0
0.1 1.0
0.12 1.0
0.14 1.0
0.16 1.0
0.18 1.0
0.2 1.0
0.22 1.0
0.24 1.0
0.26 1.0
0.28 1.0
0.3 1.0
我的代码看起来像这样,
import NumPy as np
import math
f = open('partA-imag.dat' , "r").
lines = f.readlines().
#file.close().
x_axis = [].
y_axis = [].
for line in lines:
x,y = line.split().
x_axis.append(x).
y_axis.append(y).
print(x,y).
print(x_axis).
print(y_axis).
plt.plot(x_axis,y_axis).
plt.show()
解决方案
lines = f.readlines()
x_ = []
y_ = []
for line in lines:
x, y = line.split(' ')
x_.append(float(x.rstrip()))
y_.append(float(y.rstrip()))
推荐阅读
- python - 如何识别文件夹路径并将其删除?
- c++ - 将exe输出实时保存到文本文件
- parsing - 如何在 Prolog 中创建与另一个相反的 DCG 规则?
- c++ - CUPS-filter :什么是 CUPS 开发者包
- c# - 如何以最佳方式将 float/double/half 转换为 minifloat(改进我已经工作的代码)?
- shell - 如何防止数据丢失?用于计数的 Bash 脚本 - cronjob
- python - Django PayPal 用于关联自动电子邮件发送
- vagrant - 创建磁盘 Hyperv Windows 10 时出现 Vagrant 错误
- syntax - 乔姆斯基层次结构和机器人框架
- youtube - 下载 youtube 数据时出现“YouTube 说:无法提取视频数据”