You are viewing documentation about an older version (1.11.1). View latest version

snowflake.snowpark.functions.ntile

snowflake.snowpark.functions.ntile(e: Union[int, Column, str]) Column[source]

Divides an ordered data set equally into the number of buckets specified by n. Buckets are sequentially numbered 1 through n.

Parameters:

e – The desired number of buckets; must be a positive integer value.

Example:

>>> from snowflake.snowpark.window import Window
>>> df = session.create_dataframe(
...     [["C", "SPY", 3], ["C", "AAPL", 10], ["N", "SPY", 5], ["N", "AAPL", 7], ["Q", "MSFT", 3]],
...     schema=["exchange", "symbol", "shares"]
... )
>>> df.select(col("exchange"), col("symbol"), ntile(3).over(Window.partition_by("exchange").order_by("shares")).alias("ntile_3")).show()
-------------------------------------
|"EXCHANGE"  |"SYMBOL"  |"NTILE_3"  |
-------------------------------------
|Q           |MSFT      |1          |
|N           |SPY       |1          |
|N           |AAPL      |2          |
|C           |SPY       |1          |
|C           |AAPL      |2          |
-------------------------------------
Copy