'Python: Formatting a Pandas dataframe head with LaTex

I have made a Pandas dataframe from several NumPy arrays and tried to format columns heads using LaTex, but it looks awful. I'm working with Jupyter Notebook.

import numpy as np
import pandas as pd

Arrays (one instance out of five) look like this:

coeficientes = [0.5601, 0.3315, 0.2260, 0.1429, 0.0695]
coeficientes = np.array(coeficientes)

The dataframe:

tabla_resumen = pd.DataFrame({'$x_{n-i+1}$': submuestra1, 
                              '$x_{i}$': submuestra2, 
                              '$x_{n-i+1} - x_{i}$': diferencias, 
                              '$a_{n-i+i}$': coeficientes,
                              '$(x_{n-i+1} - x_{i})(a_{n-i+i})$': sumandos
                             })
tabla_resumen

The way it looks:

enter image description here

Are there any formatting options to make it look better?



Solution 1:[1]

Try this:

Function to convert to subscript

def get_sub(x):

normal = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-=()"
sub_s = "??CD??G?????????Q?????w??Z??????????????????????w??????????????????"
res = x.maketrans(''.join(normal), ''.join(sub_s))
return x.translate(res)

Display subscript

print('H{}SO{}'.format(get_sub('2'),get_sub('4'))) #H?SO?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1