I have a dataframe with values such as 164684564.0 (type is float 64)
I just want to remove all the “.0″s from these numbers
"{:g}".format
did not work and https://stackoverflow.com/a/38283006/16796767 did not work either
Another thing: I don’t want to convert in scientific numbers (I did it once but I don’t remember the code I used). I also tried something else which occurred “cannot use this on series” error
A magical working answer would be greatly appreciated :)
Advertisement
Answer
You can use the method astype from the class DataFrame:
>> df = pd.DataFrame([[1.0], [2.0], [3.0]], columns=['Pop']) >> print(df) Pop 0 1.0 1 2.0 2 3.0 >> df = df.astype(int) >> print(df) Pop 0 1 1 2 2 3