-
Notifications
You must be signed in to change notification settings - Fork 76
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: add DataFrame|LazyFrame.unpivot
method
#1043
Conversation
return self._from_native_frame( | ||
pa.concat_tables( | ||
[ | ||
pa.Table.from_arrays( | ||
[ | ||
*[native_frame.column(idx_col) for idx_col in index_], | ||
pa.array([on_col] * n_rows, pa.string()), | ||
native_frame.column(on_col), | ||
], | ||
names=[*index_, variable_name, value_name], | ||
) | ||
for on_col in on_ | ||
] | ||
) | ||
) |
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.
Adapted from the following StackOverflow Answer
var_name=variable_name if variable_name is not None else "variable", | ||
value_name=value_name if value_name is not None else "value", |
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.
That's because passing None
(from the default of narwhals DataFrame) will overwrite the pandas default value of "value"
DataFrame|LazyFrame.unpivot
for all backends
DataFrame|LazyFrame.unpivot
for all backendsDataFrame|LazyFrame.unpivot
method
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.
awesome!
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.
thanks @FBruzzesi !
What type of PR is this? (check all applicable)
Related issues
Plotly will most likely need this feature if they decide to use narwhals
Checklist
If you have comments or can explain your changes, please do so below.