[英]Trying to fix the "Truth value of a Series is Ambiguous" Error on Pandas / Python
[英]how to fix truth value of series error in python
if train['Item_Fat_Content']=='LF':
train['Item_Fat_Content']='Low Fat'
錯誤 :
The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
您在問整列['Item_Fat_Content']
是否是LF
,這不是一個有意義的比較。 相反,您可以使用str.replace
:
train['Item_Fat_Content']=train['Item_Fat_Content'].str.replace('LF', 'Low Fat')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.