Reference an existing column by name. This is the primary way to reference columns in expressions. The returned expression will extract values from the specified column when evaluated. Args: name: The name of the column to reference Returns: A ColumnExpr t
(name: str)
| 2004 | |
| 2005 | @PublicAPI(stability="beta") |
| 2006 | def col(name: str) -> ColumnExpr: |
| 2007 | """ |
| 2008 | Reference an existing column by name. |
| 2009 | |
| 2010 | This is the primary way to reference columns in expressions. |
| 2011 | The returned expression will extract values from the specified |
| 2012 | column when evaluated. |
| 2013 | |
| 2014 | Args: |
| 2015 | name: The name of the column to reference |
| 2016 | |
| 2017 | Returns: |
| 2018 | A ColumnExpr that references the specified column |
| 2019 | |
| 2020 | Example: |
| 2021 | >>> from ray.data.expressions import col |
| 2022 | >>> # Reference columns in an expression |
| 2023 | >>> expr = col("price") * col("quantity") |
| 2024 | >>> |
| 2025 | >>> # Use with Dataset.with_column() |
| 2026 | >>> import ray |
| 2027 | >>> ds = ray.data.from_items([{"price": 10, "quantity": 2}]) |
| 2028 | >>> ds = ds.with_column("total", col("price") * col("quantity")) |
| 2029 | """ |
| 2030 | return ColumnExpr(name) |
| 2031 | |
| 2032 | |
| 2033 | @PublicAPI(stability="beta") |