for Country in energy:
if energy[Country] == 'United States':
這是遍歷熊貓中稱爲能量的DataFrame。能源所有國家都按國家字母順序列出列。 df energy如果我在如果陳述中寫出來,但如果我只是做返回,它總是會給我一個ValueError。ValueError:一個Series的真值不明確。使用a.empty,a.bool(),a.item(),a.any()或a.all()。進行字符串比較
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-61-e820508b0b91> in <module>()
20
21 return energy
---> 22 answer_one()
<ipython-input-61-e820508b0b91> in answer_one()
16
17 for Country in energy:
---> 18 if energy[Country] == 'United States':
19 return
20
/opt/conda/lib/python3.5/site-packages/pandas/core/generic.py in __nonzero__(self)
890 raise ValueError("The truth value of a {0} is ambiguous. "
891 "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
--> 892 .format(self.__class__.__name__))
893
894 __bool__ = __nonzero__
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
不要在問題中放置數據鏈接,在問題中插入示例,沒有人希望點擊未知的外部鏈接。 – Ding
你可以給出整個錯誤跟蹤 – depperm
@Ding對不起,第一次發佈,該鏈接去圖像DataFrame的結構。 – veridian