ValueError:系列的真值不明确。熊猫

问题描述 投票:0回答:1

我使用了以下代码:

data1['Close'].shift(freq='1d').pct_change(data1['Low'])

由于某种原因它将返回:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

您能告诉我为什么会出现该错误吗?

我已经在看起来像这样的数据上使用了它:

                   High           Low          Open         Close    Volume  \
Date                                                                           
2018-01-02  10495.200195  10404.650391  10477.549805  10442.200195  153400.0   
2018-01-03  10503.599609  10429.549805  10482.650391  10443.200195  167300.0   
2018-01-04  10513.000000  10441.450195  10469.400391  10504.799805  174900.0   
2018-01-05  10566.099609  10520.099609  10534.250000  10558.849609  180900.0   
2018-01-08  10631.200195  10588.549805  10591.700195  10623.599609  169000.0   
                 ...           ...           ...           ...       ...   
2020-04-15   9261.200195   8874.099609   9196.400391   8925.299805  879100.0   
2020-04-16   9053.750000   8821.900391   8851.250000   8992.799805  719400.0   
2020-04-17   9324.000000   9091.349609   9323.450195   9266.750000  684200.0   
2020-04-20   9390.849609   9230.799805   9390.200195   9261.849609  726400.0   
2020-04-21   9044.400391   8909.400391   9016.950195   8942.099609       0.0   
python-3.x pandas valueerror
1个回答
1
投票

我相信您需要按shift计算的百分比变化:

1 - data1['Low'].div(data1['Close'].shift(freq='1d'))

或:

s = data1['Close'].shift(freq='1d')
data1['Low'].sub(s).div(s)
© www.soinside.com 2019 - 2024. All rights reserved.