Skip to content

Float format syntax #2502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jorgsk opened this issue Dec 12, 2012 · 3 comments
Closed

Float format syntax #2502

jorgsk opened this issue Dec 12, 2012 · 3 comments

Comments

@jorgsk
Copy link

jorgsk commented Dec 12, 2012

In for exampe DataFrame.to_csv there is the option "float_format" with the following description:

float_format : string, default None

Format string for floating point numbers

The currently allowed format in Pandas follows the "old" Python style of '%.2f' % 1.234, so you have to write

float_format = '%.df'.

Being used to 2.7 and 3.x formatting style of Python, I expected that just ':.2f' or even '.2f' would be valid.

To keep up with the new formatting style, should these two last variants (or one of them) also be accepted in Pandas? If not, it should be specified in the documentation, perhaps with an example, that the '%'-style is required.

@paulproteus
Copy link

Thinking out loud about how to fix this:

This could be addressed with either:

  • a note in the documentation, or
  • with a test case for the new floating point format and then an implementation of it.

The best fix would be to write a test for the new floating point format, and then an implementation for it.

To find the corresponding code, namely the "to_csv" function, you can search with:

git grep "def to_csv"

showing a match in pandas/core/frame.py. The documentation is also right there, in the same file.

@dmvianna
Copy link

dmvianna commented Jan 8, 2013

This issue leads to other limitation: As it is, one cannot easily set a float_format string that could handle comma as thousands separator or currency strings (i.e., "${:,}" for

"${:,}".format(122222)
'$122,222'

).

@jreback
Copy link
Contributor

jreback commented Sep 28, 2013

closing in favor of master issue #4668

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants