相关疑难解决方法(0)

保存到实木复合地板文件中时如何使用新的Int64 pandas对象

我正在使用Python(Pandas)将数据从CSV转换为Parquet,以便稍后将其加载到Google BigQuery中。我有一些整数列,其中包含缺少的值,并且自Pandas 0.24.0起,我可以将它们存储为Int64 dtype。

有没有办法在镶木地板文件中使用Int64 dtype?对于找不到值的整数,我找不到干净的解决方案(因此它们在BigQuery中仍然是INTEGER)。

我尝试将其直接导入到BigQuery中,并得到了与使用Pandas转换为镶木地板时相同的错误(如下所示)。

导入带有int列的CSV,其中包含缺少的值:

import pandas as pd
df = pd.read_csv("docs/test_file.csv")
print(df["id"].info())
Run Code Online (Sandbox Code Playgroud)

ID 8非空float64

该行被导入为float64。我将类型更改为Int64:

df["id"] = df["id"].astype('Int64')
print(df["id"].info())
Run Code Online (Sandbox Code Playgroud)

ID 8非空Int64

然后,我尝试保存到实木复合地板上:

df.to_parquet("output/test.parquet")
Run Code Online (Sandbox Code Playgroud)

错误:

pyarrow.lib.ArrowTypeError:('未传递numpy.dtype对象','类型为Int64的列ID转换失败')

python google-bigquery parquet pyarrow

5
推荐指数
1
解决办法
837
查看次数

标签 统计

google-bigquery ×1

parquet ×1

pyarrow ×1

python ×1