Skip to content

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

Closed
@kolibril13

Description

@kolibril13

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'])

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions