首页 > 解决方案 > ValueError 递归但不是在开始时:

问题描述

我在下面的代码中收到以下错误。

ValueError:Series 的真值不明确。使用 a.empty、a.bool()、a.item()、a.any() 或 a.all()。

def calculatepct(gems,pct):

if pct < 0:        

    pct = 0

    not_in_dictionary = True        

    for child in acap1051.itertuples():

        if child.gems == gems:

            not_in_dictionary = False

            if child.parent_gems_ in all_children['gems'].values:

                mask1 = all_children[all_children["gems"] == child.parent_gems_]

                if all_children.loc[mask1.index.item()]['calculated'] == -1:

                    calculatepct(child.parent_gems_,all_children.loc[mask1.index.item()]['calculated'])

该代码适用于两个周期,但在此行之后出现值错误:

mask1 = all_children[all_children["gems"] == child.parent_gems_]

标签: pythonpandas

解决方案


推荐阅读