How to convert pandas dataframe to snowpark dataframe?
Asked Answered
A

2

7

How to convert pandas dataframe back to snowpark dataframe?

pandas_df = snowpark_df.to_pandas()
...
???
Amorphous answered 16/8, 2022 at 22:41 Comment(5)
Can you give us more context?Formalin
A snowpark dataframe is a table in Snowflake. So, use write_pandas() to write the data in the dataframe back to a Snowflake table, and then you can set that table to be a snowpark dataframe.Stagner
Basically getting snowflake table into Snowpark, dataframe, converting it to pandas to take advantage of the functionality, and once transformed, save it back to snowflake.Amorphous
Mike, the write_pandas only works with snowflake connector, and not snowpack library, right?Amorphous
Snowpark supports write_pandas. Proof: github.com/snowflakedb/snowpark-python/blob/…Formalin
W
12

Try this:

session.create_dataframe(pandas_df)

or alternatively this:

session.write_pandas(pandas_df, ...)

You can read about it in the docs here and here.

Wrens answered 5/9, 2022 at 22:31 Comment(2)
Could not edit the answer to update the link. Docs regarding createDataFrame. And docs regarding write_pandas.Brout
Thanks, I've just updated the links in the answerWrens
C
1

I am late but here you go:

import pandas as pd
from snowflake.snowpark import Session, Table


session: Session = ...
table_name = "table"
column_name = "column"

pandas_df = pd.DataFrame({"table_name": [table_name], "column_name": [column_name]})

snowpark_df = session.create_dataframe(data=pandas_df)
Chartres answered 11/4, 2024 at 19:9 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.