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

groupby - transform not working with multiple columns #6585

Closed
behzadnouri opened this issue Mar 10, 2014 · 2 comments
Closed

groupby - transform not working with multiple columns #6585

behzadnouri opened this issue Mar 10, 2014 · 2 comments
Milestone

Comments

@behzadnouri
Copy link
Contributor

I came across this issue while looking at the this question on stackoverflow;

say I have a data-frame like:

>>> df
  tag  val1  val2
0   B     0     0
1   A     1     2
2   A     2     4
3   B     3     6
4   B     4     8

and I want to reverse columns val1 and val2 within each tag; this works like a charm:

>>> grb = df.groupby('tag')
>>> df['val1'] = grb['val1'].transform(lambda ts: ts.loc[::-1])
>>> df['val2'] = grb['val2'].transform(lambda ts: ts.loc[::-1])
>>> df
  tag  val1  val2
0   B     4     8
1   A     2     4
2   A     1     2
3   B     3     6
4   B     0     0

but, if I want to do this at the same time for columns val1 and val2, it breaks:

>>> grb = df.groupby('tag')
>>> grb['val1', 'val2'].transform(lambda obj: obj.loc[::-1])
   val1  val2
0     0     0
1     1     2
2     2     4
3     3     6
4     4     8

[5 rows x 2 columns]

obviously I will not get the correct answer if I overwrite df with the new data ( or append the new columns ); however, this

>>> grb = df.groupby('tag')
>>> grb['val1', 'val2'].transform(lambda obj: obj.values[::-1])
   val1  val2
0     4     8
1     2     4
2     1     2
3     3     6
4     0     0

[5 rows x 2 columns]

works as expected; which makes me guess this has something to do with the index being aligned with the original data-frame, whereas in here it should be ignored;

@jreback jreback added this to the 0.14.0 milestone Mar 10, 2014
@jreback
Copy link
Contributor

jreback commented Mar 10, 2014

this might be fixed by this: #5264

if not, pls submit a PR (its just a small fix I think)

@jreback jreback modified the milestones: 0.14.1, 0.14.0 May 1, 2014
@jreback
Copy link
Contributor

jreback commented Jun 17, 2014

this is not a bug and works as expected

@jreback jreback closed this as completed Jun 17, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants