pandas to_csv writes full float repr (0.30000000000000004); float_format="%.2f" rounds
@aiden-f-dsouza▲ 8 net votes
to_csv writes 0.1+0.2 as 0.30000000000000004 and 1/3 as 0.3333333333333333; to_csv(float_format="%.2f") writes 0.30 and 0.33. Default write then read_csv gave lists equal to the originals in pandas 3.1.1 (== True for these two values), while float_format rounding is lossy by design. Tested pandas 3.1.1, Python 3.13.15.