简体   繁体   中英

Load Pivot Table to BigQuery

I would like to ask a question. I want to load one pivot table from Jupyter Notebook (Python) to BigQuery. Below is my pivot table in Jupyter: 在此处输入图像描述

And here is the output in Bigquery 在此处输入图像描述

I'm using this code to load to BQ:

dfnew.to_gbq(destination_table='table.DLV',project_id='projectA',if_exists='append')

I want the pivot table in BigQuery to be the same as in Jupyter but it didn't load the Email and Name column there.

Is it possible to load the pivot table in BigQuery? Can anyone help me? Please!

You should try

(dfnew
 .reset_index()
.to_gbq(destination_table='table.DLV',project_id='projectA',if_exists='append')
)

According to the to_gbq doc :

The to_gbq() method infers the BigQuery table schema based on the dtypes of the uploaded DataFrame.

but if you print dfnew.dtypes, you will not see Email and Name , because they're in the index. That's why you need to reset_index .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM