Float formatting - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Float formatting (/thread-14713.html) |
Float formatting - ambush - Dec-13-2018 import pandas as pd import numpy as np df3 = pd.DataFrame({ 'T': [11.0,22.0,11.23,20.03], 'v2': [11.0,13.0,55.1,33.0], 'v3' : [112.1,2.0,2.1,366.0], 'v4': [np.nan, "blue", 1.0, 2.0] }) df3['T'] = np.nan_to_num(df3['T']).astype(int) print(df3['T'])output is 0 11 1 22 2 11 3 20 Name: T, dtype: int32 The column T has values 11.0 ,22.0 ,11.23,20.03 the output should be like 11,22,11.23,20.03 how to remove the zeros and retain the other values after decimal(.) RE: Float formatting - Axel_Erfurt - Dec-13-2018 maybe astype(float) df3['T'] = np.nan_to_num(df3['T']).astype(float)
|