-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: groupby.pct_change() does not work properly in Pandas 0.23.0. Grouping is ignored. #21200
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
I can see the pct_change function in groupby.py on line ~3944 is not implementing this properly. Whereas the method it overrides implements it properly for a dataframe. I'd like to think this should be relatively straightforward to remedy. |
maybe related to #11811 |
groupby
followed by pct_change
does not work properly in Pandas 0.23.0. Grouping is ignored.
Found something along these lines when you shift in reverse so
The alternate method gives you correct output rather than shifting in the calculation.
|
A workaround for this is using
|
There was a bug introduced in pandas 0.23.* using pct_change() on a groupby. Details at pandas-dev/pandas#21200
Code Sample
Problem description
When there are different groups in a dataframe, by using
groupby
it is expected that thepct_change
function be applied on each group. However, combininggroupby
withpct_change
does not produce the correct result.Output:
Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.3.final.0
python-bits: 64
OS: Darwin
OS-release: 17.5.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.23.0
pytest: 3.2.1
pip: 10.0.1
setuptools: 36.5.0.post20170921
Cython: 0.26.1
numpy: 1.14.3
scipy: 0.19.1
pyarrow: None
xarray: None
IPython: 6.1.0
sphinx: 1.6.3
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2018.3
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.2
feather: None
matplotlib: 2.1.0
openpyxl: 2.4.8
xlrd: 1.1.0
xlwt: 1.2.0
xlsxwriter: 1.0.2
lxml: 4.1.1
bs4: 4.6.0
html5lib: 0.9999999
sqlalchemy: 1.1.13
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: