【问题标题】:GCP AI Platform cannot read .SAV file stored in Google Cloud Storage (Python)GCP AI Platform 无法读取存储在 Google Cloud Storage (Python) 中的 .SAV 文件
【发布时间】:2020-07-30 19:20:46
【问题描述】:

我有一个使用 Python3 笔记本设置的 AI Platform VM 实例。我还有一个包含大量 .CSV 和 .SAV 文件的 Google Cloud Storage 存储桶。我使用 Pandas 等标准 python 包从 CSV 文件中读取数据没有任何困难,但我的笔记本似乎无法在我的存储桶中找到我的 .SAV 文件。

有谁知道这里发生了什么和/或我该如何解决这个问题?

import numpy as np
import pandas as pd
import pyreadstat

df = pd.read_spss("gs://<STORAGE_BUCKET>/datafile.sav")

---------------------------------------------------------------------------
PyreadstatError                           Traceback (most recent call last)
<ipython-input-10-30836249273f> in <module>
----> 1 df = pd.read_spss("gs://<STORAGE_BUCKET>/datafile.sav")

/opt/conda/lib/python3.7/site-packages/pandas/io/spss.py in read_spss(path, usecols, convert_categoricals)
     41 
     42     df, _ = pyreadstat.read_sav(
---> 43         path, usecols=usecols, apply_value_formats=convert_categoricals
     44     )
     45     return df

pyreadstat/pyreadstat.pyx in pyreadstat.pyreadstat.read_sav()

pyreadstat/_readstat_parser.pyx in pyreadstat._readstat_parser.run_conversion()

PyreadstatError: File gs://<STORAGE_BUCKET>/datafile.sav does not exist!

【问题讨论】:

    标签: python pandas google-cloud-platform google-cloud-storage spss


    【解决方案1】:

    read_spss function 只能从本地文件路径读取:

    path: pathstr 或 Path - 文件路径。

    read_csv function比较:

    filepath_or_bufferstr: str,路径对象或类文件对象 - 任何有效的字符串路径都是可接受的。该字符串可以是一个 URL。有效的 URL 方案包括 http、ftp、s3、gs 和文件。对于文件 URL,需要一个主机。

    【讨论】:

      猜你喜欢
      • 2020-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-22
      • 2022-06-11
      • 1970-01-01
      • 2019-10-11
      • 1970-01-01
      相关资源
      最近更新 更多