我只是尝试读取上传到 GCS 的 csv 文件。
我想读取使用 GCP 中的云功能上传到 GCS 的 csv 文件。我想将 csv 数据作为“DataFrame”处理。
但是我无法使用 Pandas 读取 csv 文件。
这是使用云函数读取 GCS 上的 csv 文件的代码。
def read_csvfile(data, context):
try:
bucket_name = "my_bucket_name"
file_name = "my_csvfile_name.csv"
project_name = "my_project_name"
# create gcs client
client = gcs.Client(project_name)
bucket = client.get_bucket(bucket_name)
# create blob
blob = gcs.Blob(file_name, bucket)
content = blob.download_as_string()
train = pd.read_csv(BytesIO(content))
print(train.head())
except Exception as e:
print("error:{}".format(e))
Run Code Online (Sandbox Code Playgroud)
当我运行 Python 代码时,出现以下错误。
No columns to parse from file
一些网站说该错误意味着我读取了非空的 csv 文件。但实际上我上传了非空的csv …
csv python-3.x pandas google-cloud-platform google-cloud-functions