【问题标题】:Pyarrow Error when Querying from Big Query从 Big Query 查询时出现 Pyarrow 错误
【发布时间】: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


【解决方案1】:

我修复了同样的问题,我也在下面尝试了,但没有成功。

pip install --upgrade google-cloud-bigquery[pandas]

最后我只是删除了我的 virtualenv 中的所有包(实际上我只是删除了 env 文件夹)然后重新安装了它们(实际上我只是做了一个新的 virtualenv 和安装了我需要的包)

安装后

pip install google-cloud-bigquery

我唯一需要做的额外的事情就是。

pip install google-cloud-bigquery[pandas]

我确定您可以删除 google-cloud-biguqery 及其依赖项,作为直接删除 virtualenv 并重新制作它的更优雅的解决方案。

【讨论】:

    【解决方案2】:

    试试这个:
    import pandas as pd query_string = """ SELECT * FROM Table limit 10; """
    df = pd.read_gbq(query_string,project_id,dialect='standard')

    【讨论】:

    • 这是一个不同的库,由于需要授权,我无法使用它,它不是 google-bigquery 库。
    猜你喜欢
    • 1970-01-01
    • 2018-12-25
    • 1970-01-01
    • 1970-01-01
    • 2017-10-23
    • 1970-01-01
    • 2012-10-21
    • 1970-01-01
    • 2018-05-14
    相关资源
    最近更新 更多