Python Script to Convert CSV File to HTML Table Using Pandas Library Full Tutorial For Beginners

Python Script to Convert CSV File to HTML Table Using Pandas Library Full Tutorial For Beginners

 

Welcome folks today in this blog post we will be converting csv file to html table using pandas library full tutorial for beginners. All the source code of the tutorial will be given below.

 

 

Get Started

 

 

In order to get started we need to install the following library

 

 

pip install pandas

 

 

Just install this pandas library and now create a app.py file and copy paste the following code

 

 

 

import pandas as pd 
  
# to read csv file named "samplee" 
a = pd.read_csv("users.csv") 
  
# to save as html file 
# named as "Table" 
a.to_html("Table.html") 
  
# assign it to a  
# variable (string) 
html_file = a.to_html()

 

 

 

Now create a users.csv file inside your root directory of your project like this

 

 

name,age
gautam,23
kane,30

 

 

 

See also  Python 3 PyGame Bomberman Maze Arcade Game Script GUI Desktop App Full Project For Beginners

 

 

 

And if you run this script by executing the below command

 

 

python app.py

 

 

and now a table.html file will be created in the root folder of your project like below.

 

 

 

 

 

Leave a Reply