Skip to content

Handle European decimal formats in to_csv #781

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
adamklein opened this issue Feb 15, 2012 · 10 comments
Closed

Handle European decimal formats in to_csv #781

adamklein opened this issue Feb 15, 2012 · 10 comments
Labels
Enhancement IO CSV read_csv, to_csv IO Data IO issues that don't fit into a more specific label Output-Formatting __repr__ of pandas objects, to_string
Milestone

Comments

@adamklein
Copy link
Contributor

Counterpart to issue #584

@wesm
Copy link
Member

wesm commented Nov 27, 2012

Need to build a low-level CSV-emitter at some point. tabling this to future release

@ghost
Copy link

ghost commented Jan 20, 2014

closed by #584, 2 years ago.

@ghost ghost closed this as completed Jan 20, 2014
@bertrandhaut
Copy link
Contributor

Should this issue really be closed?

If I'm not wrong, the support of "," as decimal separtor is now (=pandas 0.14) only supported in "read_csv" and not in "to_csv".

DataFrame.to_csv only supports the float_format argument which does not allow to specify a particular decimal separtor.

@jreback
Copy link
Contributor

jreback commented Aug 20, 2014

well float format can be a function so you can do anything u want

that said

this issue was closed several years ago
if u would like to request this feature pls open a new issue with an example use case

pull requests are welcome.

@jorisvandenbossche
Copy link
Member

Isn't the feature request quite clear? Just to be able to specify decimal in to_csv like it is available in read_csv. Eg:

df.to_csv('test.csv', sep=';', decimal=',')

The linked issues which would have closed this, did not yet actually close it, as that handled about the parser, not to write.

@bertrandhaut
Copy link
Contributor

Indeed Joris has my point. For me the closed linked issue does not answer to the initial demand stated in this particular issue.

Concerning the ability of the float_format to handle a function, it seems a little too complex.

If I do a

def commaFloat(x):
    return str(x)

df.to_csv(fileName, sep=';', float_format=commaFloat() )

I get

TypeError: unsupported operand type(s) for %: 'function' and 'float'

I have to do the following in order to have it working

class commFloat:
    def __mod__(self, x):
        return str(x).replace('.',',')

Not very intuitive

@jreback jreback added this to the 0.15.1 milestone Aug 22, 2014
@bertrandhaut
Copy link
Contributor

I can try implement this feature.

Does anybody has a better proposal that just adding a:

if decimal:
       value.replace('.', decimal, 1)

after the application of the float_format function ?
Something more efficient?

@jreback
Copy link
Contributor

jreback commented Sep 26, 2014

start with adding the keyword to the top fo the call stack: https://github.com/pydata/pandas/blob/master/pandas/core/frame.py#L1071

(then need to propogate downwards)

add ulitamtely to FloatArrayFormatter. I belive you can do this all at once (its an array of float values). so no need to do indivdually. But I think the right idea.

@bertrandhaut
Copy link
Contributor

I've created a pull request for this issue: #8448

It's my first contribution to pandas and first use of git: feel free to comment.

@jreback jreback modified the milestones: 0.16.0, 0.17.0 Jan 26, 2015
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 6, 2015
@jreback
Copy link
Contributor

jreback commented Mar 7, 2015

closed by #8448

@jreback jreback closed this as completed Mar 7, 2015
dan-nadler pushed a commit to dan-nadler/pandas that referenced this issue Sep 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement IO CSV read_csv, to_csv IO Data IO issues that don't fit into a more specific label Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants