简体   繁体   中英

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. Instead, you can use str.replace :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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