Skip to content
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

Feature request: easier digit format in to_latex() #26278

Closed
kolibril13 opened this issue May 3, 2019 · 3 comments · Fixed by #40422
Closed

Feature request: easier digit format in to_latex() #26278

kolibril13 opened this issue May 3, 2019 · 3 comments · Fixed by #40422

Comments

@kolibril13
Copy link

Easier digit format

It is possible to change the digit format for the columns in a latex table like this

import pandas as pd
data  = [[1,2,3],
         [4,5,6],
         [7,8,9.001]]
df = pd.DataFrame(data, columns=['a', 'b', 'c'], index = ["foo", "bar" , "ho"])
cm0 =lambda x:'%1i'   %x
cm1 =lambda x:'%1.1f' %x
cm3= lambda x:'%1.3f' %x
format= [cm0, cm1, cm3]
latex_tab = df.to_latex( formatters= format)
print(latex_tab)

However it is really inconvenient to define everytime a new lambda function. It would be great if there would be the option:

latex_tab = df.to_latex( data, formatters_col= ['%1i','%1.1f','%1.3f'])

Furthermore, changing the digits for one row is even more difficult. It would be great to have also the option

latex_tab = df.to_latex( data, formatters_index= ['%1i','%1.1f','%1.3f'])
@WillAyd
Copy link
Member

WillAyd commented May 3, 2019

I think the first request here is reasonable and probably not a lot of effort. If you'd like to take a look and submit a PR would certainly be welcome

Not sure about the second as AFAIK we don't provide row-wise styling elsewhere in the codebase, though I could be wrong with that

@WillAyd WillAyd added IO LaTeX to_latex Code Style Code style, linting, code_checks labels May 3, 2019
@WillAyd WillAyd added this to the Contributions Welcome milestone May 3, 2019
@simonjayhawkins
Copy link
Member

I think the first request here is reasonable and probably not a lot of effort. If you'd like to take a look and submit a PR would certainly be welcome

agreed.

Not sure about the second as AFAIK we don't provide row-wise styling elsewhere in the codebase, though I could be wrong with that

ignoring the second feature request, could make the api change simpler. change the current formatters parameter to accept list of strings or a callables (or maybe mixed?). no need for additional arguments.

@simonjayhawkins simonjayhawkins removed the Code Style Code style, linting, code_checks label Dec 11, 2019
@wgranados
Copy link

take

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