StratoDem / pandas-js

Pandas in JavaScript for data analysis and visualization
https://stratodem.github.io/pandas.js-docs
MIT License
458 stars 36 forks source link

Melt equivalent? #60

Open akre54 opened 4 years ago

akre54 commented 4 years ago

Hi there - is there an equivalent to https://pandas.pydata.org/docs/reference/api/pandas.melt.html for pivoting columns?

My csv looks like this:

id,name,type,2000-01-31,2000-02-29,2000-03-31,2000-04-30
102001,demo,test,70759,70760,70767,70815

I'd like the resulting dataframe to look like:

[
  {id: 102001, name: 'demo', type: 'test', date: '2000-01-31', value: 70759},
  {id: 102001, name: 'demo', type: 'test', date: '2000-02-29', value: 70760},
  {id: 102001, name: 'demo', type: 'test', date: '2000-03-31', value: 70767},
  {id: 102001, name: 'demo', type: 'test', date: '2000-04-30', value: 70815}
]

In pandas I'd write that as:

pd.melt(trends,
  id_vars =['id','name','type'],
  var_name='date',
  value_name='value'
)

Not sure how active this project is, but hopefully this helps someone