(at: pa.Table)
| 1041 | |
| 1042 | # Normalize the numeric columns (i.e. B and C) for each group. |
| 1043 | def normalize(at: pa.Table): |
| 1044 | r = at.select("A") |
| 1045 | sb = pa.compute.sum(at.column("B")).cast(pa.float64()) |
| 1046 | r = r.append_column("B", pa.compute.divide(at.column("B"), sb)) |
| 1047 | sc = pa.compute.sum(at.column("C")).cast(pa.float64()) |
| 1048 | r = r.append_column("C", pa.compute.divide(at.column("C"), sc)) |
| 1049 | return r |
| 1050 | |
| 1051 | mapped = grouped.map_groups(normalize, batch_format="pyarrow") |
| 1052 |