0

I'm generating this html code from a dataframe, like the one in the example, but the col_space parameter, from the to_html function, isn't being applied in the final code.


df = pd.DataFrame({'calorias':[200, 350, 550], 'gordura (%)':[0, 6, 15]}, index=['banana', 'prato feito', 'big mac'])

comida calorias gordura (%)
banana 200 0
prato feito 350 6
big mac 550 15

df.to_html(classes='table table-striped', border=0, index=False, justify='left', col_space="100px")
<table border="0" class="dataframe table table-striped">\n  <thead>\n    <tr style="text-align: left;">\n      <th style="min-width: 100px;">calorias</th>\n      <th style="min-width: 100px;">gordura (%)</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <td>200</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <td>350</td>\n      <td>6</td>\n    </tr>\n    <tr>\n      <td>550</td>\n      <td>15</td>\n    </tr>\n  </tbody>\n</table>'
  • 1
    I don't understand. It outputs a `"min-width: 100px"`. Isn't it what the parameter is supposed to do? – gmolnar Jan 04 '22 at 18:16
  • Agree with @gmolnar according to the [doc](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_html.html) `col_space` is _The minimum width of each column in CSS length units._ which should be and is translated into `min-width: 100px;` see -> https://stackoverflow.com/q/18503849/4413446 – Romain Jan 04 '22 at 19:56
  • That was it! I was able to see the HTML better and it's working now. – Lucas Thaynan Jan 06 '22 at 14:58

0 Answers0