首页 > 解决方案 > 获取 pyarrow.lib.ArrowInvalid:CSV 解析错误:预期 9 列,得到 1

问题描述

所以我第一次尝试 apache arrow 并想将整个 txt 文件目录读入 pyarrow 数据结构。我正进入(状态


pyarrow.lib.ArrowInvalid: CSV parse error: Expected 9 columns, got 1

当我运行下面的代码时?不知道如何调试它。任何帮助表示赞赏。如果有一本涵盖 python 和 pyarrow 的书也很高兴阅读它。


import pyarrow.csv as csv

import pyarrow as pa  


l_all_files = ['x08.txt', 'x21.txt', 'x108.txt']

read_options = csv.ReadOptions( column_names= ('Sol' , 'H20', 'H50', 'H100',  'Date', 'Cv', 'Dys', 'Ple' , 'Cl') ,  skip_rows=26)


df_arrow_all = pa.concat_tables(( csv.read_csv(current_filename,read_options=read_options, ) for current_filename in l_all_files))  

当 skip_rows = 26 完成时,这就是该行的样子


$sss        3431    3232    3249  25523  35.66    57  56le   77.73

标签: csvpyarrow

解决方案


delmt = '\t' 
df = csv.read_csv(current_filename
                 ,read_options=read_options
                 ,parse_options=csv.ParseOptions(delimiter=delmt)

这对我有用!信用:@迈克67


推荐阅读