Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append new column to a Snowpark DataFrame with simple string

I've started using python Snowpark and no doubt missing obvious answers based on being unfamiliar to the syntax and documentation. I would like to do a very simple operation: append a new column to an existing Snowpark DataFrame and assign with a simple string. Any pointers to the documentation to what I presume is readily achievable would be appreciated.

like image 885
Dave-C Avatar asked Nov 15 '25 22:11

Dave-C


1 Answers

You can do this by using the function with_column in combination with the lit function. The with_column function needs a Column expression and for a literal value this can be made with the lit function. see documentation here: https://docs.snowflake.com/en/developer-guide/snowpark/reference/python/api/snowflake.snowpark.functions.lit.html

from snowflake.snowpark.functions import lit 
snowpark_df = snowpark_df.with_column('NEW_COL', lit('your_string'))
like image 118
udabyd2 Avatar answered Nov 18 '25 13:11

udabyd2



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!