无法将xlsx从pandas写入GCS

2024-06-11 05:59:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个奇怪的问题

我将气流作为数据管道触发K8S作业。最后,我需要将数据帧作为.parquet.xlsx文件写入Google云存储

[...]
export_app.to_parquet(f"{output_path}.parquet")
export_app.to_excel(f"{output_path}.xlsx")

拼花文件一切正常,但xlsx有一个错误

severity: "INFO"
textPayload: "[Errno 2] No such file or directory: 'gs://my_bucket/incidents/prediction/2020-04-29_incidents_result.xlsx'

我尝试将该文件写入csv以进行尝试

export_app.to_parquet(f"{output_path}.parquet")
export_app.to_csv(f"{output_path}.csv")
export_app.to_excel(f"{output_path}.xlsx")

我每次都会收到相同的消息,并按预期找到另一个文件

写xlsx文件有什么限制吗

我在我的环境中安装了包openpyxl


Tags: 文件csvto数据pathappoutput管道
1条回答
网友
1楼 · 发布于 2024-06-11 05:59:38

根据要求,我正在传递一些代码,说明我是如何直接使用gcs python3 api创建新的xlsx文件的。我使用了this教程和这个api reference

# Imports the Google Cloud client library
from google.cloud import storage

# Instantiates a client
storage_client = storage.Client()

# Create the bucket object
bucket = storage_client.get_bucket("my-new-bucket")

#Confirm bucket connected
print("Bucket {} connected.".format(bucket.name))

#Create file in the bucket
blob = bucket.blob('test.xlsx')
with open("/home/vitooh/test.xlsx", "rb") as my_file:
    blob.upload_from_file(my_file)

我希望这会有帮助

相关问题 更多 >