-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Pivot table #6075
base: main
Are you sure you want to change the base?
feat: Pivot table #6075
Conversation
I was working from the pivot table query that has been floating around. Someone would need to comment that the java way is preferred before making any changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note that in your example in the PR description, it's missing the import for pivot
:
from deephaven.experimental.pivot import pivot
And include an example with multiple Rows selected:
from deephaven import empty_table
from deephaven.experimental.pivot import pivot
y = empty_table(1000).select(["Row=ii%10", "Row2=ii%7", "Col=(int)((ii/10) % 30)", "Sentinel=random()"]).where(
"Sentinel > 0.3")
ys = y.sum_by(["Row", "Row2", "Col"])
pvt = pivot(ys, ["Row", "Row2"], "Col", "Sentinel")
pvt2 = pivot(ys, ["Row", "Row2"], "Col", "Sentinel", lambda x: f"Col_{x}")
Is there a way to convert to a tree table when we have multiple rows? Such that you can expand/collapse the sections.
value_to_col_name (Optional[Callable[[Any],str]]): A function that converts a value to a column name. | ||
The function should return a string that is a valid column name. | ||
If None (default), a string representation of the value is used as the column name, with invalid | ||
characters replaced by underscores. The character replacement is not guaranteed to produce unique | ||
column names. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think confusingly worded... it's called value_to_col_name
, and says it converts a "value to a column name", which in your example I would expect to be the sum_by value (e.g. values in the Sentinel
column); but it's actually receiving the value from within the column_col
.
def pivot(table: Table, row_cols: Union[str, Sequence[str]], column_col: str, value_col: str, | ||
value_to_col_name: Optional[Callable[[Any], str]] = None) -> Table: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would assume for true pivot tables, customers will ask to be able to pass in an array for columns and values as well, similar to Excel: https://support.microsoft.com/en-us/office/pivotby-function-de86516a-90ad-4ced-8522-3a25fac389cf
Add support for computing pivot tables.
Example: