簡體   English   中英

無法從 pandas 將 xlsx 寫入 GCS

[英]Cannot write xlsx to GCS from pandas

我有一個奇怪的問題。

我從 airflow 觸發 K8S 作業作為數據管道。 最后,我需要將 dataframe 作為.parquet.xlsx文件寫入 Google Cloud Storage。

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

鑲木地板文件一切正常,但 xlsx 出現錯誤。

嚴重性:“信息”
textPayload:“[Errno 2] 沒有這樣的文件或目錄:'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 文件有什么限制嗎?

我的環境中安裝了 package openpyxl

根據要求,我傳遞了一些代碼,我如何直接使用 gcs python3 api 創建新的 xlsx 文件。 我使用了這個教程和這個api 參考

# 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)

我希望它會有所幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM