Skip to content

to_csv locale dependent float_format #11812

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

Open
Winand opened this issue Dec 10, 2015 · 6 comments
Open

to_csv locale dependent float_format #11812

Winand opened this issue Dec 10, 2015 · 6 comments
Labels
Bug IO CSV read_csv, to_csv

Comments

@Winand
Copy link
Contributor

Winand commented Dec 10, 2015

Python (3.4) doesn't support "%n"%9.0, have to use "{:n}".format(9.0) instead.
But pandas (0.17.0) to_native_types uses 1st type of string formatting, so locale dependent format cannot be used with to_csv .

@jreback
Copy link
Contributor

jreback commented Dec 10, 2015

can you show an example of where this is failing?

@jreback jreback added the IO CSV read_csv, to_csv label Dec 10, 2015
@Winand
Copy link
Contributor Author

Winand commented Dec 11, 2015

I set locale.setlocale(locale.LC_NUMERIC, '') and want floats to use local decimal point symbol. This can be achieved with "{:n}".format(value), but pandas uses %-formatting for strings (inside to_native_types function) which doesn't support %n format (as of Python 3.4 x64 Win 7)

This works:
df.to_csv(buf, sep='\t', header=header, index=False, float_format="%g")

These don't:
df.to_csv(buf, sep='\t', header=header, index=False, float_format="%n") (Python %-formatting doesn't know %n format)
df.to_csv(buf, sep='\t', header=header, index=False, float_format="{:n}") (pandas uses %-formatting)

P.S. maybe this refers to Python issues and this issue should be closed?

@jreback
Copy link
Contributor

jreback commented Dec 11, 2015

@Winand I think we should simply change to the new style formatting here.

Want to do a pull-request?

@jreback jreback added the Bug label Dec 11, 2015
@jreback jreback added this to the Next Major Release milestone Dec 11, 2015
@Winand
Copy link
Contributor Author

Winand commented Jan 25, 2016

#12132 (though some things changed in 9302811)

@SeeminSyed
Copy link

Should this be closed as a result of work on #12132?

@Winand
Copy link
Contributor Author

Winand commented May 7, 2020

Should this be closed as a result of work on #12132?

I've never finished that PR, and now it needs to be revised, because those parts of pandas have changed significantly. But it still uses old-style formatting, afaik.

@mroeschke mroeschke added IO CSV read_csv, to_csv and removed IO CSV read_csv, to_csv good first issue labels Apr 21, 2021
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO CSV read_csv, to_csv
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants