| [ Web Proxy ] |
| Viewing: https://dataframes.bigquery.dev/reference/api/bigframes.ml.compose.SQLScalarColumnTransformer.html | [Back] [Original] |
Section Navigation
Wrapper for plain SQL code contained in a ColumnTransformer.
Create a single column transformer in plain sql. This transformer can only be used inside ColumnTransformer.
When creating an instance {0} can be used as placeholder for the column to transform:
SQLScalarColumnTransformer({0}+1)
The default target column gets the prefix transformed_ but can also be changed when creating an instance:
SQLScalarColumnTransformer({0}+1, inc_{0})
Examples:
>>> from bigframes.ml.compose import ColumnTransformer, SQLScalarColumnTransformer
>>> import bigframes.pandas as bpd
>>> df = bpd.DataFrame({'name': ["James", None, "Mary"], 'city': ["New York", "Boston", None]})
>>> col_trans = ColumnTransformer([
... ("strlen",
... SQLScalarColumnTransformer("CASE WHEN {0} IS NULL THEN 15 ELSE LENGTH({0}) END"),
... ['name', 'city']),
... ])
>>> col_trans = col_trans.fit(df)
>>> df_transformed = col_trans.transform(df)
>>> df_transformed
transformed_name transformed_city
0 5 8
1 15 6
2 4 15
[3 rows x 2 columns]
SQLScalarColumnTransformer can be combined with other transformers, like StandardScaler:
>>> col_trans = ColumnTransformer([
... ("identity", SQLScalarColumnTransformer("{0}", target_column="{0}"), ["col1", "col5"]),
... ("increment", SQLScalarColumnTransformer("{0}+1", target_column="inc_{0}"), "col2"),
... ("stdscale", preprocessing.StandardScaler(), "col3"),
... # ...
... ])
Copyright 2019, Google.
Created using Sphinx 8.1.3.
Built with the PyData Sphinx Theme 0.19.0.
| Web Proxy Viewer | New URL | Original Page |