【发布时间】:2021-07-29 08:18:33
【问题描述】:
运行下面的代码时,我收到 pyarrow 错误。我已经安装了 pyarrow,但仍然遇到同样的错误。我可以访问表格并查看架构等,但在复制与 Google Bigquery 文档相同的代码时,to_dataframe() 不起作用。
from google.cloud import bigquery
from google.oauth2 import service_account
key_path = key_path #personal json file
credentials = service_account.Credentials.from_service_account_file(
key_path, scopes=["https://www.googleapis.com/auth/cloud-platform"],
)
client = bigquery.Client(credentials=credentials, project=credentials.project_id,)
query = """
select *
from `table`
limit 10;
"""
df = client.query(query).to_dataframe() # I have also tried with df = client.query(query).result().to_dataframe()
我在运行时收到以下错误:
ValueError: The pyarrow library is not installed, please install pyarrow to use the to_arrow() function.
【问题讨论】:
-
如果你在 python shell 中运行
import pyarrow会发生什么? -
导入没有问题。与以前的查询相同的错误消息。
-
我在我的环境中尝试了您的代码。你可以试试“pip install --upgrade google-cloud-bigquery[pandas]”吗?此安装添加了一些可能已丢失的库。并检查版本是否兼容。在我的环境中,库版本如下: google-cloud-bigquery, Version: 2.16.0 和 pyarrow, Version: 3.0.0 。我建议这样做是因为我无法重新创建问题,因为您的代码对我来说非常好。
标签: python pandas google-bigquery pyarrow