7
팬더 API를 사용하여 데이터 프레임으로 읽은 csv 파일이 있습니다. 기본 첫 행 대신 자체 헤더를 설정하려고합니다. (나는 또한 행의 일부를 제거합니다.) 어떻게 이것을 가장 잘 수행 할 수 있습니까? - 그때pandas.read_csv를 사용하여 헤더 설정
df.columns = header_row
를 통해 설정을 열 시도
File "third_party/py/pandas/io/parsers.py", line 187, in read_csv
File "third_party/py/pandas/io/parsers.py", line 160, in _read
File "third_party/py/pandas/io/parsers.py", line 628, in get_chunk
File "third_party/py/pandas/core/frame.py", line 302, in __init__
File "third_party/py/pandas/core/frame.py", line 388, in _init_dict
File "third_party/py/pandas/core/internals.py", line 1008, in form_blocks
File "third_party/py/pandas/core/internals.py", line 1036, in _simple_blockify
File "third_party/py/pandas/core/internals.py", line 1068, in _stack_dict
IndexError: index out of bounds
header_row=['col1','col2','col3','col4', 'col1', 'col2'] # note the header has duplicate column values
df = pandas.read_csv(csv_file, skiprows=[0,1,2,3,4,5], names=header_row)
이것은 다음과 같은 오류를 제공합니다 :
난 다음 그러나이 예상대로 작동하지 않았다 시도 그러나이 오류는 중복 된 열 값 때문에 발생했을 수 있습니다.File "engines.pyx", line 101, in pandas._engines.DictIndexEngine.get_loc
(third_party/py/pandas/src/engines.c:2498)
File "engines.pyx", line 107, in pandas._engines.DictIndexEngine.get_loc
(third_party/py/pandas/src/engines.c:2447)
Exception: ('Index values are not unique', 'occurred at index entity')
팬더 0.7.3 버전을 사용하고 있습니다. 문서에서 -
이름 : 열 이름의 배열과 같은 목록
내가 여기에 간단하게 뭔가를 놓친 거지 확신합니다. 어떤 도움을 주셔서 감사합니다.
참고해 주셔서 감사합니다. 중복 된 열 값에 대한 요구 사항을 재검토하고 제거했습니다. – Manju