Screen Link:
My Code:
laptops[“weight”] = laptops[“weight”].str.replace(“kg”, “”).str.replace(“kgs”, “”).astype(float)
What I expected to happen:
I tired to remove “kg” and “kgs” from values in the “weight” column and to convert them into float data type.
What actually happened:
Then I got an error message like below:
ValueError: could not convert string to float: ‘4s’
Replace this line with the output/error
I changed the order of the code, so str.replace(“kgs”, “”) comes before str.replace(“kg”, “”), and I could run the program as expected.
I don’t understand why I have to remove “kgs” before “kg”…!