Python Forum

Full Version: Float formatting
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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(.)
maybe astype(float)

df3['T'] = np.nan_to_num(df3['T']).astype(float)

Output:
0 11.00 1 22.00 2 11.23 3 20.03 Name: T, dtype: float64