Skip to content
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

Melt equivalent? #60

Open
akre54 opened this issue May 20, 2020 · 0 comments
Open

Melt equivalent? #60

akre54 opened this issue May 20, 2020 · 0 comments

Comments

@akre54
Copy link

akre54 commented May 20, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant