I'm using the following code to insert a Pandas dataframe with multiple NaN
values into a BigQuery table. The dataframe is prepared in 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)
I'm getting the following error because of the NaN
values in the dataframe:
RequestException: HTTP request failed: Invalid JSON payload received.
Unexpected token. : "user_id": NaN,
^
I know that JSON
does not understand NaN
but I can't just use fillna
to convert those NaN
values to something else as I need to have those fields inserted as null
in the BigQuery table.
Does anyone have a workaround for this?