Issue
I have '\n' after > and spaces before <. Is there a way to don't save them when I call to_html method?
I have:
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
I want to have:
<table border="1" class="dataframe"><thead><tr style="text-align: right;">
I tried escape=False
, sparsify=True
, justify='center'
but it didn't work.
Solution
You can try package minify-html
:
from minify_html import minify
import pandas as pd
df = pd.DataFrame(
{
"a": [1, 1, 1, 1],
"b": [1, 2, 3, 4],
"c": [np.nan, 6, 7, 8],
}
)
s = minify(df.to_html(index=False))
print(s)
Prints:
<table border=1 class=dataframe><thead><tr style="text-align: right;"><th>a<th>b<th>c<tbody><tr><td>1<td>1<td>NaN<tr><td>1<td>2<td>6.0<tr><td>1<td>3<td>7.0<tr><td>1<td>4<td>8.0</table>
Answered By - Andrej Kesely
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.