pandas.DataFrame.to_csv float_format parameter not working as expected with pandas.Float64Dtype dtype · Issue #45991 · pandas-dev/pandas (original) (raw)

Reproducible Example

import pandas as pd
print(f"pd.__version__ = {pd.__version__}")

df = pd.DataFrame({'a':[1.1, 2.02, 3.003, 4.0004, None, 6.000006], 'b':['a', 'b', 'c', 'd', 'e', 'f']})
df.to_csv('test_float_format_no_convert_dtypes.csv', index=False, float_format='%.5f')

df_converted = df.convert_dtypes()
df_converted.to_csv('test_float_format_yes_convert_dtypes.csv', index=False, float_format='%.5f')

When np.float64 / expected result:

a,b
1.10000,a
2.02000,b
3.00300,c
4.00040,d
,e
6.00001,f

When pd.Float64Dtype (row 6 should be 6.00001):

a,b
1.1,a
2.02,b
3.003,c
4.0004,d
,e
6.000006,f