【发布时间】:2019-10-19 03:02:49
【问题描述】:
我正在使用 Python (Pandas) 将数据从 CSV 转换为 Parquet,以便稍后将其加载到 Google BigQuery 中。我有一些包含缺失值的整数列,因为 Pandas 0.24.0 我可以将它们存储为 Int64 dtype。
有没有办法在镶木地板文件中也使用 Int64 dtype?对于缺少值的整数,我找不到干净的解决方案(因此它们在 BigQuery 中保持为 INTEGER)。
我尝试将其直接导入 BigQuery 并得到与使用 Pandas 转换为 parquet 时相同的错误(如下所示。)
导入包含缺失值的 int 列的 CSV:
import pandas as pd
df = pd.read_csv("docs/test_file.csv")
print(df["id"].info())
id 8 非空 float64
该行被导入为 float64。我将类型更改为 Int64:
df["id"] = df["id"].astype('Int64')
print(df["id"].info())
id 8 非空 Int64
然后我尝试保存到镶木地板:
df.to_parquet("output/test.parquet")
错误:
pyarrow.lib.ArrowTypeError: ('Did not pass numpy.dtype object', 'Conversion failed for column id with type Int64')
【问题讨论】:
-
专门针对 BigQuery,您在下面得到了答案。但一般来说,要写入 Parquet,pyarrow 首先需要添加对可为空的 Int64 类型的支持,这是一个悬而未决的问题:issues.apache.org/jira/browse/ARROW-5379
标签: python google-bigquery parquet pyarrow