You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importnumpyasnpimportpandasaspddata=pd.DataFrame(np.random.rand(5,2), columns=['s', 't'])
print(data.rename(columns={'s' : '$s$ in m', 't' : '$t$ in s'}).to_latex(escape=False))
# would be cool to write insteadprint(data.to_latex(header=['$s$ in m', '$t$ in s'], escape=False))
# this works as expectedprint(data.to_csv(header=['$s$ in m', '$t$ in s'], escape=False))
Problem description
The header option of to_latex does not rename the columns as in other exporting functions and forces to rename them before.
I am not sure if this is a bug or intended.
But it is counterintuitive (at least for me) and makes code harder to read.
Expected Output
# would be cool to write insteadprint(data.to_latex(header=['$s$ in m', '$t$ in s'], escape=False))
Currently, the header kwarg only takes True/False to determine whether the header file is written or not written at all.
Adding the possibility to specify a list to overwrite the column names seems fine (since this is indeed how it works for to_csv).
I can try to solve the bug, but I would consider myself still a python noob compared to you guys.
But anyway:
I looked around in the source and made some test.
It is not only a problem of to_latex but of export functions which rely on fmt.DataFrameFormatter. (to_html, to_string and to_latex are affected)
Perhaps you might want to change the label.
Code Sample, a copy-pastable example if possible
Problem description
The header option of
to_latex
does not rename the columns as in other exporting functions and forces to rename them before.I am not sure if this is a bug or intended.
But it is counterintuitive (at least for me) and makes code harder to read.
Expected Output
Output of
pd.show_versions()
pandas: 0.18.1
nose: 1.3.7
pip: 9.0.1
setuptools: 23.0.0
Cython: 0.24
numpy: 1.11.2
scipy: 0.17.1
statsmodels: None
xarray: None
IPython: 4.2.0
sphinx: 1.4.6
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.4
blosc: None
bottleneck: 1.1.0
tables: 3.2.2
numexpr: 2.6.0
matplotlib: 1.5.1
openpyxl: 2.3.2
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.2
lxml: 3.6.0
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.13
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.40.0
pandas_datareader: None
The text was updated successfully, but these errors were encountered: