Reduce a table to a single row. Equivalent to `self.groupby().reduce(*args, **kwargs)`. Args: args: reducer to reduce the table with kwargs: reducer to reduce the table with. Its key is the new name of a column. Returns: Table: Reduced t
(
self, *args: expr.ColumnReference, **kwargs: expr.ColumnExpression
)
| 1274 | @desugar |
| 1275 | @arg_handler(handler=reduce_args_handler) |
| 1276 | def reduce( |
| 1277 | self, *args: expr.ColumnReference, **kwargs: expr.ColumnExpression |
| 1278 | ) -> Table: |
| 1279 | """Reduce a table to a single row. |
| 1280 | |
| 1281 | Equivalent to `self.groupby().reduce(*args, **kwargs)`. |
| 1282 | |
| 1283 | Args: |
| 1284 | args: reducer to reduce the table with |
| 1285 | kwargs: reducer to reduce the table with. Its key is the new name of a column. |
| 1286 | |
| 1287 | Returns: |
| 1288 | Table: Reduced table. |
| 1289 | |
| 1290 | Example: |
| 1291 | |
| 1292 | >>> import pathway as pw |
| 1293 | >>> t1 = pw.debug.table_from_markdown(''' |
| 1294 | ... age | owner | pet |
| 1295 | ... 10 | Alice | dog |
| 1296 | ... 9 | Bob | dog |
| 1297 | ... 8 | Alice | cat |
| 1298 | ... 7 | Bob | dog |
| 1299 | ... ''') |
| 1300 | >>> t2 = t1.reduce(ageagg=pw.reducers.argmin(t1.age)) |
| 1301 | >>> pw.debug.compute_and_print(t2, include_id=False) # doctest: +ELLIPSIS |
| 1302 | ageagg |
| 1303 | ^... |
| 1304 | >>> t3 = t2.select(t1.ix(t2.ageagg).age, t1.ix(t2.ageagg).pet) |
| 1305 | >>> pw.debug.compute_and_print(t3, include_id=False) |
| 1306 | age | pet |
| 1307 | 7 | dog |
| 1308 | """ |
| 1309 | return self.groupby().reduce(*args, **kwargs) |
| 1310 | |
| 1311 | @trace_user_frame |
| 1312 | @desugar |