-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: formatters argument to DataFrame.to_latex() is broken #6052
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
Comments
let's call this a bug then! |
feel free to do a PR for this! |
Some investigation reveals that the issue is that |
I think you can do: |
@jreback I agree, it would be nice if those did work, but unfortunately neither of them do currently. That would definitely be worth doing, but my doc-fix PR should clarify this for now. |
Is there any example on how to use the formatters field? |
take |
The reasons why this issue was not closed are mentioned in
Documentation now states: float_format : one-parameter function or str, optional, default None
Formatter for floating point numbers. For example
``float_format="%.2f"`` and ``float_format="{{:0.2f}}".format`` will
both result in 0.1234 being formatted as 0.12. Example import pandas as pd
df = pd.DataFrame({'a': [1.0, 2.0]})
print(df.to_latex(float_format='%0.f'))
FutureWarning: In future versions `DataFrame.to_latex` is expected to utilise the base implementation of `Styler.to_latex` for formatting and rendering. The arguments signature may therefore change. It is recommended instead to use `DataFrame.style.to_latex` which also contains additional functionality.
print(df.to_latex(float_format='%0.f'))
\begin{tabular}{lr}
\toprule
{} & a \\
\midrule
0 & 1 \\
1 & 2 \\
\bottomrule
\end{tabular} Which solves the part
We are just missing now the other part
But due to the future warning, the usage of this function is going to change dramatically, so I will not work on this. |
It appears that neither the
formatters
norfloat_format
arguments toDataFrame.to_latex
work if changed from their default values. Both raise the same exception:AttributeError: 'numpy.float64' object has no attribute 'decode'
.Note: neither of these arguments has test coverage in
pandas/tests/test_format.py
My test script:
The text was updated successfully, but these errors were encountered: