【发布时间】:2022-01-24 18:47:51
【问题描述】:
我正在尝试使用 read_csv 命令将数据加载到 Polars DataFrame 中,但我不断收到此错误
RuntimeError: Any(ComputeError("Could not parse 0.5 as dtype Int64 at column 13.\n The total offset in the file is 11684833 bytes.\n\n Consider running the parser `with_ignore_parser_errors=true`\n or consider adding 0.5 to the `null_values` list."))
虽然我使用转换器参数如下:
converters = {
'Date': lambda x: datetime.strptime(x, "%b %d, %Y"),
'Number': lambda x: float(x)
}
错误仍然存在。 我也尝试使用错误中显示的参数:
with_ignore_parser_errors=TRUE
错误仍然存在。我能做些什么? 我的问题不在于解析日期,而在于解析数字。 这就是我现在所拥有的:
converters = {
'Date': lambda x: datetime.strptime(x, "%b %d, %Y"),
'Number': lambda x: float(x)
}
df_file = pl.read_csv(file_to_read, has_headers=True, converters=converters,with_ignore_parser_errors=TRUE)
【问题讨论】:
-
我也尝试使用函数作为转换器 def col_fixer(x): try: return float(x) except ValueError: return np.str df_file = pl.read_csv(file_to_read, has_headers=True,转换器=dict(B=col_fixer))
标签: python parsing numbers python-3.6 python-polars