Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何获得熊猫pct_变化的百分比结果?_Python_Pandas_Series - Fatal编程技术网

Python 如何获得熊猫pct_变化的百分比结果?

Python 如何获得熊猫pct_变化的百分比结果?,python,pandas,series,Python,Pandas,Series,我用熊猫的例子来做我想做的事: >>> s = pd.Series([90, 91, 85]) >>> s 0 90 1 91 2 85 dtype: int64 然后将pct\u change()应用于此系列: >>> s.pct_change() 0 NaN 1 0.011111 2 -0.065934 dtype: float64 好的,很公平,但是百分比增加=[(最终值-起始值)/|起始

我用熊猫的例子来做我想做的事:

>>> s = pd.Series([90, 91, 85])
>>> s
0    90
1    91
2    85
dtype: int64
然后将
pct\u change()
应用于此系列:

>>> s.pct_change()
0         NaN
1    0.011111
2   -0.065934
dtype: float64
好的,很公平,但是百分比增加=[(最终值-起始值)/|起始值|]×100

所以结果应该是
[NaN,1.11111%,-6.59341%]

我如何得到这个
*100
部分,而
pct\u change()
没有为我运行?

您只需将结果乘以
100
即可得到您想要的:

In [712]: s.pct_change().mul(100)
Out[712]: 
0         NaN
1    1.111111
2   -6.593407
dtype: float64
如果希望结果是这些值的
列表
,请执行以下操作:

In [714]: l = s.pct_change().mul(100).tolist()

In [715]: l
Out[715]: [nan, 1.1111111111111072, -6.593406593406592]
print(s.pct\u change()*100)