BUG: Parameter col_space
of to_html
method not working with multi-level columns · Issue #53885 · pandas-dev/pandas (original) (raw)
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
df = pd.DataFrame([[1,2],[3,4]]) df.columns = pd.MultiIndex.from_tuples([(1,1),(2,1)]) df.to_html(col_space=100)
Issue Description
It only sets the first column with 100px:
<thead>
<tr>
<th style="min-width: 100px;"></th>
<th>1</th>
<th>2</th>
</tr>
<tr>
<th style="min-width: 100px;"></th>
<th>1</th>
<th>1</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>1</td>
<td>2</td>
</tr>
<tr>
<th>1</th>
<td>3</td>
<td>4</td>
</tr>
</tbody>
</table>
Expected Behavior
It should set all columns with 100px:
<table border="1" class="dataframe">
<thead>
<tr>
<th style="min-width: 100px;"></th>
<th style="min-width: 100px;">1</th>
<th style="min-width: 100px;">2</th>
</tr>
<tr>
<th style="min-width: 100px;"></th>
<th style="min-width: 100px;">1</th>
<th style="min-width: 100px;">1</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>1</td>
<td>2</td>
</tr>
<tr>
<th>1</th>
<td>3</td>
<td>4</td>
</tr>
</tbody>
</table>
Installed Versions
INSTALLED VERSIONS
commit : 87cfe4e
python : 3.9.12.final.0
python-bits : 64
OS : Darwin
OS-release : 22.5.0
Version : Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8
pandas : 1.5.0
numpy : 1.23.0
pytz : 2022.4
dateutil : 2.8.2
setuptools : 65.5.0
pip : None
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.10.0
pandas_datareader: None
bs4 : None
bottleneck : None
brotli :
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.8.1
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None