Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
df = pd.DataFrame(
dict(name=['Raphael', 'Donatello'],
mask=['red', 'purple'],
weapon=['sai', 'bo staff']
)
)
print(df.style.hide(axis="index").applymap_index(lambda v: "font-weight: bold;", axis="columns").to_latex(convert_css=True))
Issue Description
I am trying to convert pandas dataframe to latex with column names in bold font at the sam time , with the code above, which results in:
\begin{tabular}{lll}
\bfseries name & \bfseries mask & weapon \\
Raphael & red & sai \\
Donatello & purple & bo staff \\
\end{tabular}
where the last column name is not in bold font.
Expected Behavior
If I do not hide index with:
print(df.style.applymap_index(lambda v: "font-weight: bold;", axis="columns").to_latex(convert_css=True))
the result will be:
\begin{tabular}{llll}
& \bfseries name & \bfseries mask & \bfseries weapon \\
0 & Raphael & red & sai \\
1 & Donatello & purple & bo staff \\
\end{tabular}
where the last column name is in bold font.
Installed Versions
INSTALLED VERSIONS
commit : 2e218d1
python : 3.8.13.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.0-53-generic
Version : #59~20.04.1-Ubuntu SMP Thu Oct 20 15:10:22 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : zh_CN.UTF-8
LOCALE : zh_CN.UTF-8
pandas : 1.5.3
numpy : 1.21.5
pytz : 2022.1
dateutil : 2.8.2
setuptools : 58.0.4
pip : 21.2.4
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.6.5
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.6.0
pandas_datareader: None
bs4 : 4.10.0
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.5.1
numba : 0.55.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.8.0
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : 2022.7