Cleaning Data Basics P12

Correct

laptops["weight"] = laptops["weight"].str.replace("kgs","").str.replace("kg","").astype(float)

Results in error : ValueError: could not convert string to float: ‘4s’

laptops["weight"] = laptops["weight"].str.replace("kg","").str.replace("kgs","").astype(float)

Why does flipping the order of kg and kgs causes the error? Thanks for the guidance

Hi @genesix32

Please go through the below post, and it will help you to understand why flipping the order gives an error.

Thank You :slightly_smiling_face:

1 Like