1
저는 파이썬 2.7을 사용 중이며 CSV 파일의 항목을 읽으려고합니다. 데이터의 처음 10 행만있는 원본 CSV의 별도 버전을 만들었고 다음 코드를 사용하여 원하는대로 작동합니다. genfromtxt의 "usecols"필드에서 Z의 인덱싱을 편집 할 수 있습니다. 내 CSV에서 특정 범위의 열을 읽으십시오.파이썬에서 큰 CSV를 읽을 수 없습니다.
import numpy as np
import array
Z = array.array('i', (i for i in range(0, 40)))
with open('data/training_edit.csv','r') as f:
data = np.genfromtxt(f, dtype=float, delimiter=',', names=True, usecols=(Z[0:32]))
print(data)
하지만 내가 출력의이 종류를 얻을 내 원래 CSV로 (X 33 열 25 행)이 코드를 사용하고 이유를 모를 때 :
Traceback (most recent call last):
File "/home/user/PycharmProjects/H-B2/Read.py", line 74, in <module>
data = np.genfromtxt(f, dtype=float, delimiter=',', names=True,usecols=(Z[0:32]))
File "/usr/lib/python2.7/dist-packages/numpy/lib/npyio.py", line 1667, in genfromtxt
raise ValueError(errmsg)
ValueError: Some errors were detected !
.
.
.
Line #249991 (got 1 columns instead of 32)
Line #249992 (got 1 columns instead of 32)
Line #249993 (got 1 columns instead of 32)
Line #249994 (got 1 columns instead of 32)
Line #249995 (got 1 columns instead of 32)
Line #249996 (got 1 columns instead of 32)
Line #249997 (got 1 columns instead of 32)
Line #249998 (got 1 columns instead of 32)
Line #249999 (got 1 columns instead of 32)
Line #250000 (got 1 columns instead of 32)
Process finished with exit code 1
(나는 점을 추가 다만 실제 출력을 단축 할 수 있지만 희망
파일에 문제가있는 것 같습니까? – Mansueli
같은 수의 행 (유효한 것으로 알고 있음)을 가진 다른 파일을 쉽게 생성 할 수 있으며 파일에 동일한 코드를 실행하여 크기 또는 형식 문제인지 확인할 수 있습니다. – alfasin
크기가 아니어야합니다. CSV 형식이 올바르지 않을 수 있습니다 (예 : 누락 된 열 등) – s16h