How do I use pandas.read_csv on Google Cloud ML?(如何在 Google Cloud ML 上使用 pandas.read_csv?)
问题描述
我正在尝试在 Google Cloud ML 上部署训练脚本.当然,我已将我的数据集(CSV 文件)上传到 GCS 的存储桶中.
I'm trying to deploy a training script on Google Cloud ML. Of course, I've uploaded my datasets (CSV files) in a bucket on GCS.
我曾经使用 read_csv 从 pandas 导入我的数据,但它似乎不适用于 GCS 路径.
I used to import my data with read_csv from pandas, but it doesn't seem to work with a GCS path.
我应该如何继续(我想继续使用 pandas)?
How should I proceed (I would like to keep using pandas) ?
import pandas as pd
data = pd.read_csv("gs://bucket/folder/file.csv")
输出:
ERROR 2018-02-01 18:43:34 +0100 master-replica-0 IOError: File gs://bucket/folder/file.csv does not exist
推荐答案
您将需要使用 tensorflow.python.lib.io
中的 file_io
来执行此操作,如图所示下面:
You will require to use file_io
from tensorflow.python.lib.io
to do that as demonstrated below:
from tensorflow.python.lib.io import file_io
from pandas.compat import StringIO
from pandas import read_csv
# read csv file from google cloud storage
def read_data(gcs_path):
file_stream = file_io.FileIO(gcs_path, mode='r')
csv_data = read_csv(StringIO(file_stream.read()))
return csv_data
现在调用上面的函数
gcs_path = 'gs://bucket/folder/file.csv' # change path according to your bucket, folder and path
df = read_data(gcs_path)
# print(df.head()) # displays top 5 rows including headers as default
这篇关于如何在 Google Cloud ML 上使用 pandas.read_csv?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Google Cloud ML 上使用 pandas.read_csv?
- pytorch 中的自适应池是如何工作的? 2022-07-12
- python-m http.server 443--使用SSL? 2022-01-01
- python check_output 失败,退出状态为 1,但 Popen 适用于相同的命令 2022-01-01
- 如何在 python3 中将 OrderedDict 转换为常规字典 2022-01-01
- 沿轴计算直方图 2022-01-01
- 如何在 Python 的元组列表中对每个元组中的第一个值求和? 2022-01-01
- 如何将一个类的函数分成多个文件? 2022-01-01
- 分析异常:路径不存在:dbfs:/databricks/python/lib/python3.7/site-packages/sampleFolder/data; 2022-01-01
- padding='same' 转换为 PyTorch padding=# 2022-01-01
- 使用Heroku上托管的Selenium登录Instagram时,找不到元素';用户名'; 2022-01-01