docs/2.developers/4.user-guide/30.data-transformation/10.table-operations.md
This section describes the basic transformations you can do with Pathway.
You can create a column in a table using the select and assignment (=) operators:
t.select(new_col=t.colA + t.colB)t.select(new_col="default value")To rename a column, you can do the same (use select) or use rename:
t.select(new_col=t.old_col)t.rename(new_col=t.old_col)You can filter rows using the filter operator:
t.filter(~pw.this.column)t.filter(pw.this.column > value)The pw.coalesce operator returns the first not-None value from the given columns:
t.select(new_col=pw.coalesce(t.colA, t.colB))t.select(new_col=pw.coalesce(t.colA, 10)You can aggregate data across the rows of the table using the groupby and reduce operators:
t.groupby(pw.this.column).reduce(sum=pw.reducers.sum(pw.this.value))
You can read our dedicated tutorial to learn more about it.
Pathway provides several reducers to use on the aggregated values:
<table class="w-full"> <thead> <tr> <th class="text-left">Reducer</th> <th class="text-left">Example</th> </tr> </thead> <tbody> <tr> <td class="text-left !align-left"> <span class="block"><a href="/developers/api-docs/reducers#pathway.reducers.any">any</a></span> </td> <td class="text-left !align-left"> <ProseCodeInline>t.groupby(t.colA).reduce(col_any=pw.reducers.any(t.colB))</ProseCodeInline> </td> </tr> <tr> <td class="text-left !align-left"> <span class="block"><a href="/developers/api-docs/reducers#pathway.reducers.argmax">argmax</a></span> </td> <td class="text-left !align-left"> <ProseCodeInline>t.groupby(t.colA).reduce(col_argmax=pw.reducers.argmax(t.colB))</ProseCodeInline> </td> </tr> <tr> <td class="text-left !align-left"> <span class="block"><a href="/developers/api-docs/reducers#pathway.reducers.argmin">argmin</a></span> </td> <td class="text-left !align-left"> <ProseCodeInline>t.groupby(t.colA).reduce(col_argmin=pw.reducers.argmin(t.colB))</ProseCodeInline> </td> </tr> <tr> <td class="text-left !align-left"> <span class="block"><a href="/developers/api-docs/reducers#pathway.reducers.avg">avg</a></span> </td> <td class="text-left !align-left"> <ProseCodeInline>t.groupby(t.colA).reduce(col_avg=pw.reducers.avg(t.colB))</ProseCodeInline> </td> </tr> <tr> <td class="text-left !align-left"> <span class="block"><a href="/developers/api-docs/reducers#pathway.reducers.earliest">earliest</a></span> </td> <td class="text-left !align-left"> <ProseCodeInline>t.groupby(t.colA).reduce(col_min=pw.reducers.earliest(t.colB))</ProseCodeInline> </td> </tr> <tr> <td class="text-left !align-left"> <span class="block"><a href="/developers/api-docs/reducers#pathway.reducers.latest">latest</a></span> </td> <td class="text-left !align-left"> <ProseCodeInline>t.groupby(t.colA).reduce(col_max=pw.reducers.latest(t.colB))</ProseCodeInline> </td> </tr> <tr> <td class="text-left !align-left"> <span class="block"><a href="/developers/api-docs/reducers#pathway.reducers.max">max</a></span> </td> <td class="text-left !align-left"> <ProseCodeInline>t.groupby(t.colA).reduce(col_max=pw.reducers.max(t.colB))</ProseCodeInline> </td> </tr> <tr> <td class="text-left !align-left"> <span class="block"><a href="/developers/api-docs/reducers#pathway.reducers.min">min</a></span> </td> <td class="text-left !align-left"> <ProseCodeInline>t.groupby(t.colA).reduce(col_min=pw.reducers.min(t.colB))</ProseCodeInline> </td> </tr> <tr> <td class="text-left !align-left"> <span class="block"><a href="/developers/api-docs/reducers#pathway.reducers.ndarray">ndarray</a></span> </td> <td class="text-left !align-left"> <ProseCodeInline>t.groupby(t.colA).reduce(col_array=pw.reducers.ndarray(t.colB))</ProseCodeInline> </td> </tr> <tr> <td class="text-left !align-left"> <span class="block"><a href="/developers/api-docs/reducers#pathway.reducers.sorted_tuple">sorted_tuple</a></span> </td> <td class="text-left !align-left"> <ProseCodeInline>t.groupby(t.colA).reduce(col_tuple=pw.reducers.sorted_tuple(t.colB))</ProseCodeInline> </td> </tr> <tr> <td class="text-left !align-left"> <span class="block"><a href="/developers/api-docs/reducers#pathway.reducers.sum">sum</a></span> </td> <td class="text-left !align-left"> <ProseCodeInline>t.groupby(t.colA).reduce(col_sum=pw.reducers.sum(t.colB))</ProseCodeInline> </td> </tr> <tr> <td class="text-left !align-left"> <span class="block"><a href="/developers/api-docs/reducers#pathway.reducers.tuple">tuple</a></span> </td> <td class="text-left !align-left"> <ProseCodeInline>t.groupby(t.colA).reduce(col_tuple=pw.reducers.tuple(t.colB))</ProseCodeInline> </td> </tr> <tr> <td class="text-left !align-left"> <span class="block"><a href="/developers/api-docs/reducers#pathway.reducers.unique">unique</a></span> </td> <td class="text-left !align-left"> <ProseCodeInline>t.groupby(t.colA).reduce(col_unique=pw.reducers.unique(t.colB))</ProseCodeInline> </td> </tr> </tbody> </table>You can also create your own stateful reducers.
You can use a join to combine columns from two different tables by associating rows from both tables which are matching on some given values:
t1.join(t2, pw.left.column == pw.right.column).select(...)
Read our tutorial about joins to learn more about how to do joins in Pathway.
You can update the cells of a table using the content of another table using the update_cells operator (<<):
t.update_cells(t_new)t << t_newYou can transform a column containing iterables or JSON arrays into multiple rows using the flatten operator:
t.flatten(t.col_to_flatten)
Pathway allows you to define your own User-defined functions. See our tutorial to learn more about it.