python - 无法从熊猫将 xlsx 写入 GCS
问题描述
我有一个奇怪的问题。
我从作为数据管道的气流触发 K8S 作业。最后,我需要将数据帧作为.parquet
和.xlsx
文件写入谷歌云存储。
[...]
export_app.to_parquet(f"{output_path}.parquet")
export_app.to_excel(f"{output_path}.xlsx")
镶木地板文件一切正常,但 xlsx 出现错误。
严重性:“INFO”
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 文件有什么限制吗?
我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)
我希望它会有所帮助!
推荐阅读
- ios - iOS DateFormatter 给出 nil ,当设备时区和区域发生变化时
- ios - UIImageView 像素化
- html - 如何将表单值双向绑定到嵌套的角度模型
- c - C- 使用内核模块显示 CPU 信息
- javascript - 尽管存在路线,但未捕获 JADE 表单提交
- .htaccess - mod_rewrite 规则 htaccess 未按预期工作
- bash - 在值之间查找多个字符串并在bash中用换行符替换
- ruby-on-rails - Rails 方法而不是模型的 has_many 中的 id
- regex - 正则表达式等于或高于 125233000
- javascript - 更新 observable 中的值而不解析先前的运算符