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

2024-09-27 07:27:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我用Python3笔记本设置了一个AI平台VM实例。我还有一个谷歌云存储桶,其中包含许多.CSV和.SAV文件。使用标准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!

Tags: 文件inimportgsdfreadbucket笔记本
1条回答
网友
1楼 · 发布于 2024-09-27 07:27:01

^{} function只能从本地文件路径读取:

path: pathstr or Path - File path.

将其与^{} function进行比较:

filepath_or_bufferstr: str, path object or file-like object - Any valid string path is acceptable. The string could be a URL. Valid URL schemes include http, ftp, s3, gs, and file. For file URLs, a host is expected.

相关问题 更多 >

    热门问题