GCP AI平台无法读取存储在Google Cloud Storage(Python)中的.SAV文件

时间:2020-07-30 19:20:46

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

我有一个使用Python3笔记本电脑设置的AI Platform VM实例。我还有一个Google Cloud Storage存储桶,其中包含许多.CSV和.SAV文件。使用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!

1 个答案:

答案 0 :(得分:4)

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

path pathstr或Path -文件路径。

将其与read_csv function进行比较:

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