25
$\begingroup$

I'm working on a Kaggle challenge where some variables are represented by rows instead of columns (Telstra Network Disruption). I am currently searching for the equivalent of gather(), separate() and spread(), which can be found in R tidyr tool.

$\endgroup$
1

4 Answers 4

8
$\begingroup$

I'd start with the melt() function in pandas. I wrote an article about it:

https://www.ibm.com/developerworks/community/blogs/jfp/entry/Tidy_Data_In_Python?lang=en

$\endgroup$
4
$\begingroup$

R's gather() essentially goes from wide to long. So,

  1. check pandas page for how to use pandas.wide_to_long(),
  2. check this blog for a discussion on getting an elegant gather-like function in Python.
$\endgroup$
2
$\begingroup$

I tried to syntactically mimic the tidyr package in python in a package called tidypython. I made it compatible with the dplython package, which includes usage of the >> operator for chaining commands.

It hasn't been fully tested, but should work pretty well:

https://github.com/durrantmm/tidypython

Let me know if it works for you.

$\endgroup$
0
$\begingroup$

There is a port of tidyr in python:

https://github.com/pwwang/datar

Disclaimer: I am the author.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.