javascriptdata / danfojs

Danfo.js is an open source, JavaScript library providing high performance, intuitive, and easy to use data structures for manipulating and processing structured data.
https://danfo.jsdata.org/
MIT License
4.77k stars 209 forks source link

Pivot table #9

Open risenW opened 4 years ago

risenW commented 4 years ago

Pivot table support for DataFrame

nite commented 3 years ago

Any updates on this? Seems like it would be a compelling feature to make this the default pandas go-to in the javascript ecosystem.

risenW commented 3 years ago

Any updates on this? Seems like it would be a compelling feature to make this the default pandas go-to in the javascript ecosystem.

We will work on this, just not in the roadmap atm. Unless someone decides to pick it up. Would you be interested ?

nite commented 3 years ago

Point me to the relevant code & I'll take a look!

tbh this is currently a bit of a blocker to me even doing a spike with danfo - but if we do it, then I'd like to know how hard it'd be to implement a pivot.

Here's a gist I wrote to do a pivot on an array of melted objects with lodash: doubt it's this easy! https://gist.github.com/nite/6ffda3d61278dccfb2152f8565492009

steveoni commented 3 years ago

@nite i don't think it will be that hard to implement, to implement pivot_table i think we need to implement how to access and display multi-index table.

But however, we can get started without the above

But with my little knowledge of pivot table, to create the main functionality for pivot_table without including some more complicated functionality as included in pandas

The main functionality of pivot_table from pandas API pivot_table(data, values=None, index=None, columns=None, aggfunc='mean') can be implemented as follows:

At the end of this operation, we would have a giant object containing the result of this operation, this object can be considered to be a graph.

To have a concrete view of the above implementation steps, you can check out pivot_table examples here: https://www.analyticsvidhya.com/blog/2020/03/pivot-table-pandas-python/ and compare them with the above implementation details.

@nite I think this is all we need to implement the main functionality of pivot_table

Cc: @risenW

risenW commented 3 years ago

Point me to the relevant code & I'll take a look!

tbh this is currently a bit of a blocker to me even doing a spike with danfo - but if we do it, then I'd like to know how hard it'd be to implement a pivot.

Here's a gist I wrote to do a pivot on an array of melted objects with lodash: doubt it's this easy! https://gist.github.com/nite/6ffda3d61278dccfb2152f8565492009

Also to add @nite You would implement this in the DataFrame class here. Your output is going to be a DataFrame, so something of this signature:

 / **
   *Some doc here
   * @return DataFrame 
   */
  pivot() {
    const data = this.values  //get the inner array representing the DataFrame
    //your pivot code to manipulate the data
    ...
    ...
    // return a new DataFrame with the pivoted values
    const df = new DataFrame(pivoted_data, { columns: this.column_names, index: indx });
    return df;
  }
rorcde commented 1 year ago

Hi everyone, are there any updates on adding pivot functionality to a dataframe? I looked at the documentation and could not find anything on this matter. It would be fantastic to have pivoting in danfo.js.

Dantos7 commented 3 months ago

That would be very useful also for me