【发布时间】:2018-10-31 16:19:51
【问题描述】:
我正在尝试读取文件
文本文件本身分为 9 列,包含大量数据(总共 454 行)
我正在尝试读取和检索某些数据列,以便绘制与温度相关的质量图(HR 图)
但是,当我尝试使用以下方式加载文本时:
file = 'nameoftext.txt' #the file itself is saved as a txt from notepad++
track1 = np.loadtext(file, skiprows=70) #im skipping 70 rows of headers to the data (and np is numpy)
我收到一条错误消息:
ValueError: could not convert string to float: 'iso'
我不知道这意味着什么或我在做什么。
我也在使用np.loadtext,因为这是我的教授向我们展示如何加载文件的唯一方法,我不知道该怎么做。
【问题讨论】:
-
Numpy 只接受数字。 CSV 中一定有混合字符串。
-
@riddler 这不完全正确,您可以将具有正确编码的字符串放入 numpy 数组中
-
如果您知道 9 列的数据类型(您应该知道),您可以像
dtype='str,int, int, str, int, int, str, float, int',一样手动指定它们。否则,您可以使用np.genfromtxt并指定dtype=None。看看here -
无需为此责怪 Jupyter。只是说
标签: python python-3.x jupyter-notebook