In the above code, the typecasted weight column is not assigned back to the weight column of laptops. Most pandas methods return a modified dataframe rather than modifying the dataframe directly. You will see a similar behaviour if you use str.replace but didn’t assign the modified column to laptops["weight"].
You can verify that no column type change happened in the above code by running laptops.info(); you’ll see that weight will have the type object instead of float.
Modifying the line to laptops["weight"] = laptops["weights"].astype(float) should give the same result as the second code.