We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
the following groupby transform results in things getting casted to object...
df = DataFrame({'d' : [1.,1.,1.,2.,2.,2.], 'c' : np.tile(['a','b','c'], 2), 'v' : np.arange(1., 7.)}) # in IPython In [34]: df Out[34]: c d v 0 a 1 1 1 b 1 2 2 c 1 3 3 a 2 4 4 b 2 5 5 c 2 6
Now write a small transform function:
def f(group): v = group['v'] group['v2'] = (v - v.min()) / (v.max() - v.min()) return group
Note that this also handles NAs since the v variable is a pandas Series object.
Now group by the d column and apply f:
In [36]: df.groupby('d').apply(f) Out[36]: c d v v2 0 a 1 1 0 1 b 1 2 0.5 2 c 1 3 1 3 a 2 4 0 4 b 2 5 0.5 5 c 2 6 1
The text was updated successfully, but these errors were encountered:
BUG: fix GroupBy.apply bug, GH #237
82d73a9
No branches or pull requests
the following groupby transform results in things getting casted to object...
Now write a small transform function:
Note that this also handles NAs since the v variable is a pandas Series object.
Now group by the d column and apply f:
The text was updated successfully, but these errors were encountered: