Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,888 questions

51,815 answers

573 users

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 146 views
1 answer 165 views
1 answer 381 views
2 answers 241 views
1 answer 175 views
1 answer 166 views
1 answer 79 views
...