【发布时间】:2020-08-26 23:56:49
【问题描述】:
我正在做一个简单的定义,以根据一些间隔返回颜色列表。不幸的是,我不断收到以下错误:
ValueError:Series 的真值不明确。使用 a.empty、a.bool()、a.item()、a.any() 或 a.all()。
我看过以下关于 stackoverflow 的讨论,但只是尝试使其工作失败。
Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
这是我的代码:
y = 5
std = pd.Series([1,1,1,1])
values = pd.Series([2, 4, 6, 8])
colors = []
def colorbybar():
for i in values:
if y < (values - (2*std)):
colors[i] = 'darkblue'
elif y < (values - std):
colors[i] = 'blue'
elif y < values:
colors[i] = 'white'
elif y < (values + std):
colors[i] = 'red'
elif y < (values + (2*std)):
colors[i] = 'darkred'
return colors
colorbybar()
【问题讨论】:
-
如果您的original question 没有有意义的答案,请不要post your question again。下次,编辑原始问题以改进它。
-
colors已经是一个全局变量。您无需退货。
标签: python pandas definition valueerror