Skip to content

to_clipboard issue with float_format #9449

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
jorisvandenbossche opened this issue Feb 9, 2015 · 2 comments
Open

to_clipboard issue with float_format #9449

jorisvandenbossche opened this issue Feb 9, 2015 · 2 comments
Labels
API Design Bug Output-Formatting __repr__ of pandas objects, to_string

Comments

@jorisvandenbossche
Copy link
Member

Related to #9448, using the following example:

In [143]: df = pd.DataFrame(np.random.randn(5,2), columns=['A', 'B'])

In [144]: df
Out[144]:
          A         B
0 -1.151315 -2.174735
1 -1.031375 -1.957344
2 -0.619368 -0.835133
3  2.562381 -0.294245
4  2.432353  0.032805

to_clipboard is said to pass the kwargs to to_csv (see docs: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_clipboard.html). However, that seems not be fully true for the float_format kwarg:

df.to_clipboard(float_format='%.3f')
->
    A   B
0   -1.151  -2.175
1   -1.031  -1.957
2   -0.619  -0.835
3   2.562   -0.294
4   2.432   0.033

Now using a callable:

df.to_clipboard(float_format='{:.3f}'.format)
->
       A      B
0 -1.151 -2.175
1 -1.031 -1.957
2 -0.619 -0.835
3  2.562 -0.294
4  2.432  0.033

but this does not work with to_csv:

In [150]: df.to_csv(float_format='{:.3f}'.format)
---------------------------------------------------------------------------
TypeError: unsupported operand type(s) for %: 'builtin_function_or_method' and 'float'

Furthermore, when using a function as float_format, the result is no longer pastable in excel, even with excel=True (the default).

@jorisvandenbossche jorisvandenbossche changed the title to_clipboard issues with float_format to_clipboard issue with float_format Feb 9, 2015
@jorisvandenbossche
Copy link
Member Author

OK, looking at to_clipboard, this is of course just because when to_csv fails, it is passed on to to_string. However:

  • this is not mentioned in the docs (and to_string has different parameters/defaults, so this has a impact)
  • this defeats the purpose of excel=True

@jreback
Copy link
Contributor

jreback commented Feb 10, 2015

Yeah, I think we should NOT fallback here. Forgot exactly why were doing that in the first place. So mark this a bug/API then.

@jreback jreback added Bug API Design Output-Formatting __repr__ of pandas objects, to_string labels Feb 10, 2015
@jreback jreback added this to the 0.17.0 milestone Feb 10, 2015
@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
API Design Bug Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

No branches or pull requests

5 participants