gpt4 book ai didi

r - 如何将 R 数据帧作为 CSV 文件上传到 Azure Blob 存储上?

转载 作者:行者123 更新时间:2023-12-04 01:41:15 25 4
gpt4 key购买 nike

我正在尝试将 R 中的数据帧转换为 Azure Blob 存储上的 CSV 文件。我用了AzureStor包,但它不能正确转换数据帧。我期望 16 列包含数据,但它返回一列,其中所有数据随机拆分到行中。

我使用了下面的 R 代码:

library(AzureStor)


bl_endp_key <- storage_endpoint("url", key="key")
cont <- storage_container(bl_endp_key, "containername")
csv <- serialize(dataframe, connection = NULL, ascii = TRUE)
con <- rawConnection(csv)
upload_blob(cont, src=con, dest="output.csv")

任何人都可以告诉我需要更改什么,或者给我示例代码来说明您是如何成功做到这一点的吗?

提前致谢!

最佳答案

这是我的示例代码,它工作正常。

library(AzureStor)

df <- data.frame(Column1 = c('Value 1', 'Value 2', 'Value 3'),
Column2 = c('Value 1', 'Value 2', 'Value 3'))

account_endpoint <- "https://<your account name>.blob.core.windows.net"
account_key <- "<your account key>"
container_name <- "<your container name>"
bl_endp_key <- storage_endpoint(account_endpoint, key=account_key)
cont <- storage_container(bl_endp_key, container_name)
w_con <- textConnection("foo", "w")
write.csv(df, w_con)
r_con <- textConnection(textConnectionValue(w_con))
close(w_con)
upload_blob(cont, src=r_con, dest="df.csv")
close(con)

df.csv的内容如下。

"","Column1","Column2"
"1","Value 1","Value 1"
"2","Value 2","Value 2"
"3","Value 3","Value 3"

希望有帮助。

关于r - 如何将 R 数据帧作为 CSV 文件上传到 Azure Blob 存储上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57307893/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com