Dask read_csv fails where pandas doesn't

白昼怎懂夜的黑 提交于 2020-02-02 00:58:07

问题


Trying to use dask's read_csv on file where pandas's read_csv like this

dd.read_csv('data/ecommerce-new.csv')

fails with the following error:

pandas.errors.ParserError: Error tokenizing data. C error: EOF inside string starting at line 2

The file is csv file of scraped data using scrapy with two columns, one with the url and the other with the html(which is stored multiline using " as delimiter char). Being actually parsed by pandas means it should be actually well-formatted.

html,url
https://google.com,"<a href=""link"">
</a>"

Making the sample argument big enough to load the entire file in memory seems to work, which makes me believe it actually fails when trying to infer the datatypes(also there's this issue which should have been solved https://github.com/dask/dask/issues/1284)

Has anyone encountered this problem before? Is there a fix/workaround?

EDIT: Apparently this is a known problem with dask's read_csv if the file contains a newline character between quotes. A solution I found was to simply read it all in memory:

dd.from_pandas(pd.read_csv(input_file), chunksize=25)

This works, but at the cost of parallelism. Any other solution?


回答1:


For people coming here in 2020, the dd.read_csv works directly for newlines inside quotes. It has been fixed. Update to latest version of dask to get these benefits.



来源:https://stackoverflow.com/questions/45752805/dask-read-csv-fails-where-pandas-doesnt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!