PivotTable(rows, columns, calculation)
Source¶
One row per group of rows and one column per value of a column, used by Table.pivot_table.
Added in version 0.1.0
Parameters:
-
rows(list[str])The names of the columns whose values form the rows of the result: one row per combination of values, sorted, with missing values as a group of their own, last. The pivot table keeps its own copy of the list.
-
columns(str)The name of the column whose values become the columns of the result, sorted. It cannot hold missing values. The values are written as texts:
"Paris","8"for 8 and 8.0,"2.5","2026-12-31". -
calculation(Calculation)
Raises:
-
InvalidTypeErrorWhen a setting is not of the type its annotation names.
-
EmptyListErrorWhen
rowsis an empty list. -
InvalidColumnNameErrorWhen
columnsor a name inrowsis an empty text. -
DuplicateColumnErrorWhen a name appears twice among
rowsandcolumns. -
RefusedSettingErrorWhen the calculation has a
result_name.
Examples:
import numdaplot as ndp
hours = ndp.Array.from_list([8, 8, 9])
weekdays = ndp.Array.from_list(["Mon", "Tue", "Mon"])
fares = ndp.Array.from_list([7.0, 9.0, 5.0])
trips = ndp.Table.from_arrays({"hour": hours, "weekday": weekdays, "fare": fares})
total_fare = ndp.Calculation(column="fare", function=ndp.Sum())
trips.pivot_table(ndp.PivotTable(rows=["hour"], columns="weekday", calculation=total_fare))
# hour Mon Tue
# INT64 FLOAT64 FLOAT64
# 0 8 7.0 9.0
# 1 9 5.0 0.0