Car*_*los 3 python pandas parquet pyarrow
使用 pyArrow 将 pandas.DF 转换为镶木地板时出现此错误:
ArrowInvalid('Error converting from Python objects to Int64: Got Python object of type str but can only handle these types: integer
Run Code Online (Sandbox Code Playgroud)
为了找出问题所在的列,我在 for 循环中创建了一个新的 df,首先使用第一列,然后为每个循环添加另一列。我意识到错误出现在dtype: object以 0 开头的列中,我想这就是为什么 pyArrow 想要将该列转换为int但失败的原因,因为其他值是UUID
我正在尝试传递一个架构:(不确定这是否是要走的路)
table = pa.Table.from_pandas(df, schema=schema, preserve_index=False)
Run Code Online (Sandbox Code Playgroud)
其中架构是: df.dtypes
卡洛斯您是否尝试过将列转换为此处列出的熊猫类型之一https://arrow.apache.org/docs/python/pandas.html?
你能发布 df.dtypes 的输出吗?
如果更改 pandas 列类型没有帮助,您可以定义要传入的 pyarrow 模式。
fields = [
pa.field('id', pa.int64()),
pa.field('secondaryid', pa.int64()),
pa.field('date', pa.timestamp('ms')),
]
my_schema = pa.schema(fields)
table = pa.Table.from_pandas(sample_df, schema=my_schema, preserve_index=False)
Run Code Online (Sandbox Code Playgroud)
更多信息在这里:
https://arrow.apache.org/docs/python/data.html https://arrow.apache.org/docs/python/generated/pyarrow.Table.html#pyarrow.Table.from_pandas https://arrow。 apache.org/docs/python/generated/pyarrow.schema.html
| 归档时间: |
|
| 查看次数: |
9079 次 |
| 最近记录: |