<table border="1" class="dataframe">
<thead> <tr style="text-align: right;">
<th>Student id</th> <th>Course id</th> <th>Marks</th> </tr>
</thead>
<tbody>
<tr> <td>1002</td> <td>2001</td> <td>67</td> </tr>
</tbody>
</table>
这是我的HTML表的近似结构)
您可以将输出从
sdf.to_html()
tag和通过div
import pyhtml as h
my_table = """
<table border="1" class="dataframe">
<thead> <tr style="text-align: right;">
<th>Student id</th> <th>Course id</th> <th>Marks</th> </tr>
</thead>
<tbody>
<tr> <td>1002</td> <td>2001</td> <td>67</td> </tr>
</tbody>
</table>"""
s = h.html(
h.head(
h.title("Student Data")
),
h.body(
h.h1(
"Student Details"
),
(h.div(my_table, _safe=True))
)
)
print(s.render())
<!DOCTYPE html>
<html>
<head>
<title>
Student Data
</title>
</head>
<body>
<h1>
Student Details
</h1>
<div>
<table border="1" class="dataframe">
<thead> <tr style="text-align: right;">
<th>Student id</th> <th>Course id</th> <th>Marks</th> </tr>
</thead>
<tbody>
<tr> <td>1002</td> <td>2001</td> <td>67</td> </tr>
</tbody>
</table>
</div>
</body>
</html>