首页 > 解决方案 > Dask read_csv——在`pd.read_csv`/`pd.read_table`中发现不匹配的dtypes

问题描述

我正在尝试使用 dask 读取 csv 文件,它给了我一个如下所示的错误。但问题是我想要我ARTICLE_IDobject(string)。任何人都可以帮助我成功读取数据吗?

追溯如下:

ValueError: Mismatched dtypes found in `pd.read_csv`/`pd.read_table`.

+------------+--------+----------+

| Column     | Found  | Expected |

+------------+--------+----------+

| ARTICLE_ID | object | int64    |

+------------+--------+----------+

The following columns also raised exceptions on conversion:

ARTICLE_ID:


ValueError("invalid literal for int() with base 10: ' July 2007 and 31 March 2008. Diagnostic practices of the medical practitioners for establishing the diagnosis of different types of EPTB were studied. Results: For the diagnosi\\\\'",)

Usually this is due to dask's dtype inference failing, and
*may* be fixed by specifying dtypes manually by adding:

dtype={'ARTICLE_ID': 'object'}

to the call to `read_csv`/`read_table`.

标签: pythondataframedask

解决方案


该消息建议您将呼叫从

df = dd.read_csv('mylocation.csv', ...)

df = dd.read_csv('mylocation.csv', ..., dtype={'ARTICLE_ID': 'object'})

您应该将文件位置和任何其他参数更改为您之前使用的位置。如果这仍然不起作用,请更新您的问题。


推荐阅读