[Pandas-dev] Consensus on pct_change
Matthew Brett
matthew.brett at gmail.com
Wed Jul 10 10:54:51 EDT 2019
Hi,
On Wed, Jul 10, 2019 at 7:47 AM William Ayd <william.ayd at icloud.com> 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%
Sure - of course one can display the proportions as percentages, but I
am sure you'd agree, from the definition of percentage change, that
the float 0.1 is a very surprising answer to percent change between 1
and 1.1. I mean, you'd surely mark that wrong if you were grading a
student assignment, because they failed to do the the "per cent" part
of the calculation.
Cheers,
Matthew
More information about the Pandas-dev
mailing list