Skip to content

BUG: rowspan in read_html failed #60210

Closed
@duongkstn

Description

@duongkstn

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

# html string
s = '<table>\n<caption>Đơn vị tính: Việt Nam đồng</caption>\n<tr>\n<th rowspan="2">Tổng giới hạn bồi thường / năm / người</th>\n<th>Chương trình 1</th>\n<th>Chương trình 2</th>\n<th>Chương trình 3</th>\n</tr>\n<tr>\n<td>50,000,000</td>\n<td>100,000,000</td>\n<td>200,000,000</td>\n</tr>\n<tr>\n<td>Tử vong do tai nạn</td>\n<td>50,000,000</td>\n<td>100,000,000</td>\n<td>200,000,000</td>\n</tr>\n<tr>\n<td>Thương tật toàn bộ vĩnh viễn/ năm</td>\n<td>50,000,000</td>\n<td>100,000,000</td>\n<td>200,000,000</td>\n</tr>\n<tr>\n<td>Thương tật bộ phận vĩnh viễn/ năm</td>\n<td>50,000,000</td>\n<td>100,000,000</td>\n<td>200,000,000</td>\n</tr>\n<tr>\n<td>Chi phí y tế điều trị thương tật do tai nạn/ năm</td>\n<td>10,000,000</td>\n<td>20,000,000</td>\n<td>30,000,000</td>\n</tr>\n</table>'


print(pd.read_html(s))

Issue Description

I have a HTML string (with rowspan attribute), here is how it look when rendering
image

Then I convert to dataframe by using pd.read_html command (pandas 2.2.3), here is how it looks:
image

Totally wrong, the row of 50000000, 100000000 and 200000000 should be aligned to the right.

Expected Behavior

the row of 50000000, 100000000 and 200000000 should be aligned to the right

Installed Versions

INSTALLED VERSIONS

commit : 0691c5c
python : 3.10.9
python-bits : 64
OS : Linux
OS-release : 5.15.0-124-generic
Version : #134~20.04.1-Ubuntu SMP Tue Oct 1 15:27:33 UTC 2024
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.2.3
numpy : 1.26.4
pytz : 2022.7
dateutil : 2.8.2
pip : 24.3.1
Cython : None
sphinx : 5.0.2
IPython : 8.10.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2024.3.1
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.2
lxml.etree : 4.9.1
matplotlib : None
numba : N/A
numexpr : 2.8.4
odfpy : None
openpyxl : 3.1.3
pandas_gbq : None
psycopg2 : 2.9.9
pymysql : None
pyarrow : 16.1.0
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.10.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 2.0.1
xlsxwriter : 3.2.0
zstandard : 0.19.0
tzdata : 2024.1
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

Labels

BugIO HTMLread_html, to_html, Styler.apply, Styler.applymap

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions