-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: Frequency-based shifting doesn't work with groupby and MultiIndex #11452
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
Comments
Thanks for the report. Internally I think |
@jreback #11211 makes it so that this raises an error, which is probably better than the behaviour reported, but I think frequency shifting on a multi-index where one of the indices is a datetime index would be pretty nice to have, especially in the case above, where the other index is just being used to groupby. Could |
@jreback @naught101 I got the STILL the same problem.. Giving NaN at some places.. Date is the index (descending).
Code: df_1 = df.shift(1, freq='B')
df['r1'] = (df['c']-df_1['c'])/df['c']
df['r2'] = df['c'].pct_change(freq='D') r1 is actually doing the same as pct_change() should do, but it doesn't. r2 is giving NaN at some places. Also the numbers LOOK the same, but there is a diff in them like 0.018425 != 0.018771. But I know for sure my calculation is correct RETURN = (END_PERIOD_VALUE-BEGIN_PERIOD_VALUE)/END_PERIOD_VALUE. Or do I really use the wrong pandas function..? 😕 Please fix this issue. |
@Danger89 well, see that open tag. that means it wasn't closed in a prior release. The quickest way to have something fixed is to submit a pull-request :) what you are showing as an example is not reflective of this issue in any event (and I would guess you dtypes are |
@jreback The dtype of 'c' is float64. Is that answering your remark? And it says 'dtype: object'. I'm using |
@Danger89 you have not posted a reproducible example. I suggest that you open a new issue if you think there is a bug here, otherwise SO may be able to help. |
Ow.. oke. |
This looks to be a duplicate of #10128 |
If you have a dataframe with a multiindex, and use groupby and then shift, using the frequency argument, the shifting fails, resulting in an empty result. For example:
I'm not sure why, however using 'grp' as a column, it works fine:
The text was updated successfully, but these errors were encountered: