DEV Community

Discussion on: How to Clean Data Using Pandas

Collapse
 
aredhi profile image
Ardi

at More data processing inside of detect_price function you dont need to use elif, since you directly return in that scope, so you can write like this

def detect_price(row):
    if row['Price'] > 15.50:
        return 'High'
    if row['Price'] > 5.50 and row['Price'] <= 15.50:
        return 'Medium'
    if row['Price'] > 0.0 and row['Price'] <= 5.50:
        return 'Low'
    return np.NaN

Enter fullscreen mode Exit fullscreen mode
Collapse
 
sahilfruitwala profile image
Sahil

Agreed. You are absolutely right. I was focusing more on simplicity so missed this one. ThanksπŸ™ŒπŸΌπŸ™ŒπŸΌπŸ™ŒπŸΌ