小编mar*_*227的帖子

Pandas to_gbq() TypeError“预期字节数,得到一个‘int’对象

我正在使用该pandas_gbq模块尝试将数据帧附加到 Google BigQuery 中的表中。

我不断收到此错误:

ArrowTypeError:需要字节,得到一个“int”对象。

我可以确认数据帧的数据类型与 BQ 表的架构匹配。

我发现这篇关于 Parquet 文件无法混合数据类型的文章:Pandas to parquet file

在我收到的错误消息中,我看到有一个对 Parquet 文件的引用,因此我假设该df.to_gbq()调用正在创建一个 Parquet 文件,并且我有一个混合数据类型列,这导致了错误。错误消息没有具体说明。

我认为我的挑战是我无法找到哪一列具有混合数据类型 - 我尝试将它们全部转换为字符串,然后指定表架构参数,但这也不起作用。

这是完整的错误回溯:

In [76]: df.to_gbq('Pricecrawler.Daily_Crawl_Data', project_id=project_id, if_exists='append')
ArrowTypeError                            Traceback (most recent call last)
<ipython-input-76-74cec633c5d0> in <module>
----> 1 df.to_gbq('Pricecrawler.Daily_Crawl_Data', project_id=project_id, if_exists='append')

~\Anaconda3\lib\site-packages\pandas\core\frame.py in to_gbq(self, destination_table, 
project_id, chunksize, reauth, if_exists, auth_local_webserver, table_schema, location, 
progress_bar, credentials)
   1708         from pandas.io import gbq
   1709
-> 1710         gbq.to_gbq(
   1711             self,
   1712             destination_table,

~\Anaconda3\lib\site-packages\pandas\io\gbq.py in to_gbq(dataframe, destination_table, project_id, chunksize, …
Run Code Online (Sandbox Code Playgroud)

python pandas google-bigquery

13
推荐指数
1
解决办法
2万
查看次数

标签 统计

google-bigquery ×1

pandas ×1

python ×1