简体   繁体   English

努力从 Google Cloud Storage 存储桶中读取 csv 文件

[英]Struggling to read csv files from Google Cloud Storage bucket

There are some CSV files in a folder of a GCS bucket. GCS 存储桶的文件夹中有一些 CSV 文件。 I am using these codes to access and read those CSV files as pandas dataframe:我正在使用这些代码来访问和读取这些 CSV 文件作为熊猫数据框:

from google.cloud import storage
import gcsfs
import fsspec
storage_client = storage.Client()

blobs = storage_client.list_blobs('pipe_ml-data', prefix='postive_data_file/')
all_files = list(blobs)
all_files = all_files[1::]
for blob in all_files:
    file_path = "gs://pipe_ml-data/{}".format(blob.name)
    content = pd.read_csv(file_path)
    content.head()
    break

But getting the following error:但得到以下错误:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/var/folders/9q/h73jxwsx0f1629kdwpdfmdb80000gn/T/ipykernel_31809/388262887.py in <module>
      1 from google.cloud import storage
----> 2 import gcsfs
      3 import fsspec
      4 storage_client = storage.Client()
      5 

/opt/anaconda3/lib/python3.9/site-packages/gcsfs/__init__.py in <module>
      3 __version__ = get_versions()["version"]
      4 del get_versions
----> 5 from .core import GCSFileSystem
      6 from .mapping import GCSMap
      7 

/opt/anaconda3/lib/python3.9/site-packages/gcsfs/core.py in <module>
     18 from fsspec.utils import stringify_path, setup_logging
     19 from fsspec.callbacks import NoOpCallback
---> 20 from fsspec.implementations.http import get_client
     21 from .retry import retry_request, validate_response
     22 from .checkers import get_consistency_checker

/opt/anaconda3/lib/python3.9/site-packages/fsspec/implementations/http.py in <module>
     16 from fsspec.exceptions import FSTimeoutError
     17 from fsspec.spec import AbstractBufferedFile
---> 18 from fsspec.utils import DEFAULT_BLOCK_SIZE, isfilelike, nullcontext, tokenize
     19 
     20 from ..caching import AllBytes

ImportError: cannot import name 'isfilelike' from 'fsspec.utils' (/opt/anaconda3/lib/python3.9/site-packages/fsspec/utils.py)

I already installed and imported gcsfs as well as fsspec libraries.我已经安装并导入了 gcsfs 以及 fsspec 库。 Nothing helped.没有任何帮助。 Could you please give me a solution?你能给我一个解决方案吗?

fsspec.utils.isfilelike looks to be very new , like in the last couple of months (Apr 22), so I'm going to guess you've got some sort of version issue going on (like you're importing fsspec 2022.3.0 or older instead of 2022.5.0 or newer). fsspec.utils.isfilelike 看起来很新,就像在过去几个月(4 月 22 日)一样,所以我猜你遇到了某种版本问题(比如你正在导入 fsspec 2022.3. 0 或更早版本,而不是 2022.5.0 或更高版本)。

Use a command like pip show fsspec to see if you've got 2022.5.0 or later installed.使用pip show fsspec类的命令查看您是否安装了 2022.5.0 或更高版本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将多个CSV文件从Google Cloud Bucket导入到Datalab - Importing multiple CSV files from Google Cloud Bucket to Datalab 将所有.csv文件从Google存储桶中读取到一个大熊猫df中,然后另存为.csv到另一个存储桶中 - Reading all .csv files from a google storage bucket into one large pandas df, then saving back as .csv to another bucket 使用 Python 脚本中的 Google Cloud Functions 从 Google Cloud Storage 读取 CSV - Read a CSV from Google Cloud Storage using Google Cloud Functions in Python script 如何使用 Cloud Functions 读取和修改云存储中一个存储桶上的 csv 文件并将结果保存在另一个存储桶中 - How to read and modify a csv file on one bucket in cloud storage and save the results in another bucket using Cloud Functions 如何从谷歌云存储桶中读取 python 代码中的.json 文件 - How to Read .json file in python code from google cloud storage bucket 无法从Google云存储桶读取.json - Cannot read .json from a google cloud bucket 从 Google Cloud Storage Bucket 提供静态文件(用于 GCE 上托管的 Django 应用) - Serve Static files from Google Cloud Storage Bucket (for Django App hosted on GCE) 使用 python 获取某个文件后,如何从 Google 云存储桶中获取文件? - How do you fetch files from Google cloud storage bucket after a certain file is fetched using python? 用于从Google存储桶将多个csv文件读取到1个Pandas DataFrame中的“ For”循环 - 'For' loop for reading multiple csv files from a google storage bucket into 1 Pandas DataFrame 使用谷歌云作曲家问题读取 CSV 并加载到 gcp 存储桶中 - read CSV and load into gcp bucket using google cloud composer issue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM