From 4f1724810740210e39fea36473ad5acdd0687dae Mon Sep 17 00:00:00 2001 From: Andrei Assa Date: Wed, 10 Feb 2021 20:47:10 -0500 Subject: [PATCH] Changed pct_change parameters to calculate pct_change right-to-left for axis=1. --- pandas/core/generic.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index e1271cfec2bde..19e9ba97385ac 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10205,7 +10205,10 @@ def pct_change( assert _data is not None # needed for mypy data = _data - rs = data.div(data.shift(periods=periods, freq=freq, axis=axis, **kwargs)) - 1 + if axis == 1: + rs = data.div(data.shift(periods=-periods, freq=freq, axis=axis, **kwargs)) - 1 + else: + rs = data.div(data.shift(periods=periods, freq=freq, axis=axis, **kwargs)) - 1 if freq is not None: # Shift method is implemented differently when freq is not None # We want to restore the original index