我有以下小测试,我想在雪花的内部阶段存储 xlsx 文件:
import snowflake.snowpark as snowpark
import xlsxwriter
import pandas as pd
from snowflake.snowpark.functions import col
def main(session: snowpark.Session):
# Your code goes here, inside the "main" handler.
tableName = 'information_schema.packages'
dataframe = session.table(tableName).filter(col("language") == 'python')
x = dataframe.to_pandas()
unload_location = "@JV_TEST/jv.xlsx"
x.to_excel(unload_location)
# Print a sample of the dataframe to standard output.
dataframe.show()
# Return value will appear in the Results tab.
return dataframe
但我收到以下错误:
Traceback (most recent call last):
Worksheet, line 17, in main
File "pandas/util/_decorators.py", line 211, in wrapper
return func(*args, **kwargs)
File "pandas/util/_decorators.py", line 211, in wrapper
return func(*args, **kwargs)
File "pandas/core/generic.py", line 2374, in to_excel
formatter.write(
File "pandas/io/formats/excel.py", line 944, in write
writer = ExcelWriter( # type: ignore[abstract]
File "pandas/io/excel/_xlsxwriter.py", line 205, in __init__
super().__init__(
File "pandas/io/excel/_base.py", line 1313, in __init__
self._handles = get_handle(
File "pandas/io/common.py", line 734, in get_handle
check_parent_directory(str(handle))
File "pandas/io/common.py", line 597, in check_parent_directory
raise OSError(rf"Cannot save file into a non-existent directory: '{parent}'")
OSError: Cannot save file into a non-existent directory: '@JV_TEST'
如何在阶段存储文件? (我想使用 pandas 和 xlsxwrite,因为我想将一些东西应用到 Excel 工作表)
最佳答案
目前无法使用 Python 工作表写入阶段。 Python 存储过程和 UDFs 的一般限制也适用于 Python 工作表。
这意味着您只能将文件写入 /tmp
,一旦 session 终止,将无法再从 /tmp
访问文件。
您只能使用 Python 的内置函数(如 open()
)写入 /tmp
,它不适用于 xlsxwriter
等外部函数。
作为一般规则,使用 Python 操作存储在舞台上的文件是不可能的。
关于python - Snowflake python 表存储阶段文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76482383/