# transforms.api.transform\_pandas ## transforms.api.transform\_pandas(output, \*\*inputs) {#transforms.api.transform\_pandas} Register the wrapped compute function as a pandas transform. :::callout{theme="neutral"} To use the pandas library, you must add `pandas` as a **run** dependency in your `meta.yml` file. For more information, refer to the [documentation ↗](../../../transforms-python/project-structure/index.md#metayaml). ::: :::callout{theme="success"} If you prefer using Polars DataFrames, use the [`transform_polars`](../api-transform-polars/index.md#transforms.api.transform_polars) decorator to register your compute function as a Polars transform. ::: The `transform_pandas` decorator is used to construct a [`Transform`](../api-transform/index.md#transforms.api.Transform) object from a compute function that accepts and returns [`pandas.DataFrame` ↗](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html#pandas.DataFrame) objects. This decorator is similar to the [`transform_df()`](../api-transform-df/index.md#transforms.api.transform_df) decorator, however the [`pyspark.sql.DataFrame` ↗](https://spark.apache.org/docs/latest/api/python/reference/pyspark.sql/api/pyspark.sql.DataFrame.html#pyspark.sql.DataFrame) objects are converted to [`pandas.DataFrame` ↗](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html#pandas.DataFrame) objects before the computation, and converted back afterwards. ```python >>> @transform_pandas( ... Output('/path/to/output/dataset'), # An unnamed Output spec ... first_input=Input('/path/to/first/input/dataset'), ... second_input=Input('/path/to/second/input/dataset'), ... ) ... def my_compute_function(first_input, second_input): ... # type: (pandas.DataFrame, pandas.DataFrame) -> pandas.DataFrame ... return first_input.concat(second_input) ``` :::callout{theme="success"} You can wrap a pandas transform with the [`incremental`](../api-incremental/index.md#transforms.api.incremental) decorator to run it incrementally. When `@incremental` wraps `transform_pandas`, inputs are read using the `added` mode and the write mode is determined by `@incremental`. If you need to read or write using non-default modes, use the [`transform()`](../api-transform/index.md#transforms.api.transform) decorator instead. ::: ```python >>> @incremental() ... @transform_pandas( ... Output('/path/to/output/dataset'), ... first_input=Input('/path/to/first/input/dataset'), ... ) ... def compute(first_input): ... # type: (pandas.DataFrame) -> pandas.DataFrame ... # "added" rows are provided; output write behavior is controlled by @incremental ... return first_input ``` Note that `transform_pandas` should only be used on datasets that can fit into memory. If you have larger datasets that you wish to filter down before converting to pandas you should write your transformation using the [`transform_df()`](../api-transform-df/index.md#transforms.api.transform_df) decorator and the [`pyspark.sql.SparkSession.createDataFrame()` ↗](https://spark.apache.org/docs/latest/api/python/reference/pyspark.sql/api/pyspark.sql.SparkSession.createDataFrame.html#pyspark.sql.SparkSession.createDataFrame) method. ```python >>> @transform_df( ... Output('/path/to/output/dataset'), # An unnamed Output spec ... first_input=Input('/path/to/first/input/dataset'), ... second_input=Input('/path/to/second/input/dataset'), ... ) ... def my_compute_function(ctx, first_input, second_input): ... # type: (pyspark.sql.DataFrame, pyspark.sql.DataFrame) -> pyspark.sql.DataFrame ... pd = first_input.filter(first_input.county == 'UK').toPandas() ... # Perform pandas operations on a subset of the data before converting back to a PySpark DataFrame ... return ctx.spark_session.createDataFrame(pd) ``` * **Parameters:** * **output** ([*Output*](../api-output/index.md#transforms.api.Output)) – The single [`Output`](../api-output/index.md#transforms.api.Output) spec for the transform. * **\*\*inputs** ([*Input*](../api-input/index.md#transforms.api.Input)) – `kwargs` comprised of named [`Input`](../api-input/index.md#transforms.api.Input) specs.