Skip to content

DOC: Add recipe for shifting groups of values based on the index #6917

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

Merged
merged 1 commit into from
Apr 21, 2014

Conversation

unutbu
Copy link
Contributor

@unutbu unutbu commented Apr 21, 2014

No description provided.

index=[u'Last Gunfighter', u'Last Gunfighter', u'Last Gunfighter',
u'Paynter', u'Paynter', u'Paynter']); df

df['beyer_shifted'] = df.groupby(level=0)['beyer'].apply(lambda grp: grp.shift(1)); df
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can u put the final df on next line (rather than semi colon it)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think this line is misaligned by one space with the initial df = ..

@unutbu
Copy link
Contributor Author

unutbu commented Apr 21, 2014

So edited.

jreback added a commit that referenced this pull request Apr 21, 2014
DOC: Add recipe for shifting groups of values based on the index
@jreback jreback merged commit 6fe9539 into pandas-dev:master Apr 21, 2014
@jreback
Copy link
Contributor

jreback commented Apr 21, 2014

@unutbu thanks!

@jreback jreback added the Docs label Apr 21, 2014
@jreback jreback added this to the 0.14.0 milestone Apr 21, 2014
@jreback
Copy link
Contributor

jreback commented Apr 21, 2014

It think in 0.14 enabled .shift(1) to work directly, rathern than .apply(lambda grp: grp.shift(1))

i'll fixup

@unutbu
Copy link
Contributor Author

unutbu commented Apr 22, 2014

Ah. That works as far back as 0.8.0 as well.

@unutbu
Copy link
Contributor Author

unutbu commented Apr 22, 2014

Just for fun I wanted to use git bisect to find the first commit where groupby(...).shift(1) works. I can do it manually, but this requires that I reinstall pandas to test each commit:

/bin/rm -rf ~/src/pandas/{build,dist} && cdsitepackages && /bin/rm -rf pandas*
cd ~/src/pandas && python setup.py build_ext --inplace && python setup.py install 

I suppose I could write a unittest script with a setUp method which performs the installation, and then run git bisect run .... But is there an easier, automated way?

@jreback
Copy link
Contributor

jreback commented Apr 22, 2014

ahh...that's the automatic function call generation, kind of a syntactic sugar

I don't any easier way to run git bisect....only used it a couple of times.

I think bisect will do the install for you (e.g. it checkouts a particular commit), runs setup, then runs the code....

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

Successfully merging this pull request may close these issues.

3 participants