Dav*_*tia 4 python pandas google-bigquery pyarrow
当我将数字数据(int64 或 float64)从 Pandas 数据框上传到“数字” Google BigQuery 数据类型时,出现以下错误:
pyarrow.lib.ArrowInvalid:获得长度为 8 的字节串(预期为 16)
我尝试更改 Pandas 数据框中“tt”字段的数据类型,但没有结果:
df_data_f['tt'] = df_data_f['tt'].astype('float64')
Run Code Online (Sandbox Code Playgroud)
和
df_data_f['tt'] = df_data_f['tt'].astype('int64')
Run Code Online (Sandbox Code Playgroud)
使用架构:
job_config.schema = [
...
bigquery.SchemaField('tt', 'NUMERIC')
...]
Run Code Online (Sandbox Code Playgroud)
阅读此google-cloud-python 问题报告我得到:
数字 = pyarrow.decimal128(38, 9)
因此,“数字” Google BigQuery 数据类型使用比“float64”或“int64”更多的字节,这就是 pyarrow 无法匹配数据类型的原因。
我有:
Python 3.6.4
熊猫1.0.3
pyarrow 0.17.0
谷歌云bigquery 1.24.0
我不确定这是否是最好的解决方案,但我通过更改数据类型解决了这个问题:
import decimal
...
df_data_f['tt'] = df_data_f['tt'].astype(str).map(decimal.Decimal)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11748 次 |
| 最近记录: |