首页 > 解决方案 > Why is pandas DataFrame.to_csv float_format option using the old-style formatting?

问题描述

I wanted to write a pandas DataFrame into a CSV. I wanted all floats to have 2 decimal points. So I used the new formatting style of Python:

indf.to_csv("myfile.csv", float_format="{:.2}")

But no, apparently to_csv wants the old formatting style

indf.to_csv("myfile.csv", float_format="%.2f")

Why is that?

标签: pythonpandasdataframefloating-pointformatting

解决方案


目前正在讨论这个问题。看看https://github.com/pandas-dev/pandas/issues/9448


推荐阅读