Open Irio opened 5 years ago
Hi @Irio, Thank you for your sugesstion. Sorry for the delay, I wasn't active these days.
Have you look the GroupedDataFrame .pivot
method (https://github.com/Gmousse/dataframe-js/blob/develop/src/group.js#L156) ?
It should works similarly.
Hi @Gmousse,
Yes, I have look at them, but they don't seem to cover all the cases I needed and Pandas supports. There's always the chance they are too specific, so in this case, let me know and we can close this issue.
My major pain-point was doing operations with multiple attributes, either in index, columns, or the attribute to aggregate on.
Here are all the cases I implemented using dataframe-js and are supported by Pandas:
https://colab.research.google.com/drive/1tBXUtOzTZiTli2JR1VYFODYf7wxO6PNF
And here, my attempt to reproduce them using dataframe-js@1.4.3. The only case that can be fully reproduced, at least with my understanding of the docs, is the first.
https://gist.github.com/Irio/c23af8d00768d48acecb87a41d62905e
Is your feature request related to a problem? Please describe. Pivoting is a common task in data processing. It is used when we want to calculate statistics of specific attributes.
From Pandas' documentation:
Describe the solution you'd like I've been looking to libraries capable of pivoting dataframes. Pandas, in my view, has a very complete implementation of the method.
Describe alternatives you've considered This is a need I had at work. Since I could only find one library – AlaSQL – and with only a simple implementation, that does not pivot over multiple columns or allows pivoting without explicit index, I've written my own version of the function. To derive the algorithm, I replicated the behavior seen in the
pivot_table
function of Pandas.Additional context I have already written the function, and it works for a few test cases I listed:
My function is not integrated into dataframe-js, but it works on dataframes generated with dataframe-js. Would you be interested in bringing this feature in? If so, I may need some help on reviewing it to ensure it follows the conventions of the project – of source code and unit tests. I could open a WIP pull request and we discuss the necessary changes on the go.