我正在尝试将一堆 CSV 文件从 Google Cloud Storage 读取到 pandas 数据帧中,如中所述将 csv 从 Google Cloud 存储读取到 pandas 数据框 https://stackoverflow.com/questions/49357352/read-csv-from-google-cloud-storage-to-pandas-dataframe
storage_client = storage.Client()
bucket = storage_client.bucket(bucket_name)
blobs = bucket.list_blobs(prefix=prefix)
list_temp_raw = []
for file in blobs:
filename = file.name
temp = pd.read_csv('gs://'+bucket_name+'/'+filename+'.csv', encoding='utf-8')
list_temp_raw.append(temp)
df = pd.concat(list_temp_raw)
导入 gcfs 时显示以下错误消息。我的机器上已经安装了“dask”和“gcsfs”软件包;但是,无法消除以下错误。
File "C:\Program Files\Anaconda3\lib\site-packages\gcsfs\dask_link.py", line
121, in register
dask.bytes.core._filesystems['gcs'] = DaskGCSFileSystem
AttributeError: module 'dask.bytes.core' has no attribute '_filesystems'
之间似乎存在一些错误或冲突gcsfs
and dask
包。事实上,dask
您的代码不需要库即可工作。要运行的代码的最低配置是安装库(我发布了其最新版本):
google-cloud-storage==1.14.0
gcsfs==0.2.1
pandas==0.24.1
另外,filename
已经包含了.csv
扩大。因此将第 9 行更改为:
temp = pd.read_csv('gs://' + bucket_name + '/' + filename, encoding='utf-8')
通过这些更改,我运行了您的代码并且它有效。我建议你创建一个虚拟环境并安装库并在那里运行代码 https://googleapis.github.io/google-cloud-python/latest/storage/index.html#windows:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)