How to render DataFrame as HTML table in Python

1 Answer

0 votes
import pandas as pd
 
df = pd.DataFrame(
    [['Tom', 91, 80, 94],
     ['Emmy', 98, 95, 96],
     ['Rubeus', 87, 81, 87],
     ['Dumbledore', 99, 100, 98],
     ['Axel', 75, 85, 90]],
    columns=['name', 'algebra', 'python', 'java'])
 
html = df.to_html()

print(html)
  
  
  
'''
run:
  
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>algebra</th>
      <th>python</th>
      <th>java</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>Tom</td>
      <td>91</td>
      <td>80</td>
      <td>94</td>
    </tr>
    <tr>
      <th>1</th>
      <td>Emmy</td>
      <td>98</td>
      <td>95</td>
      <td>96</td>
    </tr>
    <tr>
      <th>2</th>
      <td>Rubeus</td>
      <td>87</td>
      <td>81</td>
      <td>87</td>
    </tr>
    <tr>
      <th>3</th>
      <td>Dumbledore</td>
      <td>99</td>
      <td>100</td>
      <td>98</td>
    </tr>
    <tr>
      <th>4</th>
      <td>Axel</td>
      <td>75</td>
      <td>85</td>
      <td>90</td>
    </tr>
  </tbody>
</table>
 
'''

 



answered Jan 7, 2021 by avibootz

Related questions

1 answer 278 views
1 answer 297 views
1 answer 526 views
2 answers 391 views
1 answer 282 views
1 answer 280 views
1 answer 207 views
...