提问人:keller 提问时间:11/17/2023 最后编辑:Tim Robertskeller 更新时间:11/17/2023 访问量:19
尝试使用 np.loadtext 导入文件时,我一直收到错误“ValueError:第 1 行的列索引 2 无效,有 2 列”
I keep getting the error " ValueError: invalid column index 2 at row 1 with 2 columns" when trying to import a file using np.loadtext
问:
尝试使用 np.loadtext 导入文件时,我一直收到错误“ValueError:第 1 行的列索引 2 无效,有 2 列”。
这是我当前用于尝试导入文件的代码。
from google.colab import drive
drive.mount('/content/drive')
%matplotlib notebook
import numpy as np
import matplotlib.pyplot as plt
evo0_8f = '/content/drive/MyDrive/HR-Diagram/evo_0.8.txt'
evo0_8 = np.loadtxt(evo0_8f, skiprows=2, usecols=(1,2))
答:
0赞
Tim Roberts
11/17/2023
#1
这些列从零开始编号。你需要。usecols=(0,1)
或者,由于只有两列,因此完全跳过该参数。
评论