简体   繁体   English

如何修复python中系列错误的真值

[英]how to fix truth value of series error in python

if train['Item_Fat_Content']=='LF':
    train['Item_Fat_Content']='Low Fat'

error :错误 :

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

You are asking whether the entire column ['Item_Fat_Content'] is LF , which isn't a meaningful comparison.您在问整列['Item_Fat_Content']是否是LF ,这不是一个有意义的比较。 Instead, you can use str.replace :相反,您可以使用str.replace

train['Item_Fat_Content']=train['Item_Fat_Content'].str.replace('LF', 'Low Fat')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM