【发布时间】:2019-03-28 02:52:03
【问题描述】:
我正在使用以下代码将具有多个 NaN 值的 Pandas 数据框插入到 BigQuery 表中。数据框在 Cloud Datalab 中准备。
import google.datalab.bigquery as bq
bqtable = ('project_name', 'dataset_name', 'table_name')
table = bq.Table(bqtable)
table_schema = bq.Schema.from_data(df)
table.create(schema = table_schema, overwrite = True)
table.insert(df)
由于数据框中的 NaN 值,我收到以下错误:
RequestException: HTTP request failed: Invalid JSON payload received.
Unexpected token. : "user_id": NaN,
^
我知道JSON 不理解NaN,但我不能只使用fillna 将这些NaN 值转换为其他值,因为我需要在BigQuery 中将这些字段插入为null桌子。
有没有人有解决方法?
【问题讨论】:
标签: python-3.x pandas dataframe google-bigquery google-cloud-datalab