[英]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.