[Pandas-dev] Consensus on pct_change

Chris Bartak cbartak at gmail.com
Wed Jul 10 10:59:37 EDT 2019


I'm sure it depends on your background (mine is more financial than
academic), but at least for some users this isn't confusing or surprising -
I would say 10% is equivalent to 0.10.  Excel works that way, as well as
most pocket calculators with a '%' key.

I think of it more as an output formatting issue - it's always been a
weaker point to me in pandas compared to e.g. SAS, but not clear what the
solution is - probably some kind of formatting metadata.  Old master issue
here - https://github.com/pandas-dev/pandas/issues/4668

On Wed, Jul 10, 2019 at 9:47 AM William Ayd via Pandas-dev <
pandas-dev at python.org> wrote:

> Hi Matthew,
>
> Thanks for reaching out! I don’t really see a reason to change this as the
> use of floats to represent percentages is pretty common Python. You can
> format the output to percentages if you want doing something as follows:
>
> >>> pd.Series([1, 1.1]).pct_change().map('{:.0%}'.format)
> 0    nan%
> 1     10%
>
> Or use a (admittedly more verbose) lambda expression if you don’t want NA
> values to get formatted:
>
> >>> pd.Series([1, 1.1]).pct_change().apply(lambda x: np.nan if
> pd.isnull(x) else '{:.0%}'.format(x))
> 0    NaN
> 1    10%
>
> Someone else may have even more direct ways of approaching this.
>
> - Will
>
> On Jul 10, 2019, at 7:32 AM, Matthew Brett <matthew.brett at gmail.com>
> wrote:
>
> Hi,
>
> ## Summary
>
> The pct_change method does not give the percent change, and that's
> confusing.   What should be done to fix that?
>
> ## Problem:
>
> Consider the following snippet:
>
> [ins] In [3]: pd.Series([1, 1.1]).pct_change()
> Out[3]:
> 0    NaN
> 1    0.1
> dtype: float64
>
> Pandas thinks that the percent change from 1 to 1.1 is 0.1, but I
> think most of us would agree that this is incorrect - the *percent*
> change is 10.
>
> This is very confusing, and tripped up some of my students.
>
> There is some discussion of the problem over at this issue:
>
> https://github.com/pandas-dev/pandas/issues/20752
>
> ## What can be done?
>
> I guess the viable options could be:
>
> * Leave the method as is, but add some very clear indication in the
> docstring that the function does not return percent change, but
> proportional change.
> * Do the above, but also add a keyword like 'percent=False', that,
> when True, multiplies the result by 100.
> * Rename the method to prop_change, add back a deprecated method
> pct_change, that points to prop_change and warns about the confusion.
>
> What do y'all think?
>
> Cheers,
>
> Matthew
> _______________________________________________
> Pandas-dev mailing list
> Pandas-dev at python.org
> https://mail.python.org/mailman/listinfo/pandas-dev
>
>
> William Ayd
> william.ayd at icloud.com
>
>
>
> _______________________________________________
> Pandas-dev mailing list
> Pandas-dev at python.org
> https://mail.python.org/mailman/listinfo/pandas-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pandas-dev/attachments/20190710/f2a15b1e/attachment-0001.html>


More information about the Pandas-dev mailing list