Convert CSV to HTML Table using Python Pandas and Flask Framework Last Updated : 26 May, 2022 Comments Improve Suggest changes Like Article Like Report In this article, we are going to convert a CSV file into an HTML table using Python Pandas and Flask Framework. Sample CSV file : USERNAME,IDENTIFIER,FIRST_NAME,LAST_NAME booker12,9012,Rachel,Booker grey07,2070,Laura,Grey johnson81,4081,Craig,Johnson jenkins46,9346,Mary,Jenkins smith79,5079,Jamie,SmithStepwise ImplementationCreating Environment Step 1: Create an environment. Create a project folder and a venv folder within. py -3 -m venv venv Step 2: Activate the environment. venv\Scripts\activate Step 3: Install Flask and Pandas. pip install Flask pip install pandas Creating Project Step 1: Create ‘app.py’ folder and write the code given below. Python3 # importing flask from flask import Flask, render_template # importing pandas module import pandas as pd app = Flask(__name__) # reading the data in the csv file df = pd.read_csv('sample_data.csv') df.to_csv('sample_data.csv', index=None) # route to html page - "table" @app.route('/') @app.route('/table') def table(): # converting csv to html data = pd.read_csv('sample_data.csv') return render_template('table.html', tables=[data.to_html()], titles=['']) if __name__ == "__main__": app.run(host="localhost", port=int("5000")) Step 2: Create the folder ‘templates’. create the file ‘table.html’ inside the ‘templates’ folder. HTML <!DOCTYPE html> <html lang="en"> <head> <title> Table </title> </head> <body> <div align="center"> <table> <h1> <!--Displaying the converted table--> {% for table in tables %} <h2>{{titles[loop.index]}}</h2> {{ table|safe }} {% endfor %} </h1> </table> </div> </body> </html> Step 3: Add the 'sample_data.csv' file. Step 4: The project structure will look like this. Structure of the projectRun the Project Step 1: Run the server. Step 2: Browse the URL ‘localhost:5000’. Step 3: The output web page will be displayed. Output: Output : CSV to HTML Table Comment More infoAdvertise with us Next Article Convert CSV to HTML Table using Python Pandas and Flask Framework venniladeenan Follow Improve Article Tags : HTML Python-pandas Python-projects Python Flask Flask Projects +1 More Similar Reads Python Projects - Beginner to Advanced Python is one of the most popular programming languages due to its simplicity, versatility, and supportive community. Whether youâre a beginner eager to learn the basics or an experienced programmer looking to challenge your skills, there are countless Python projects to help you grow.Hereâs a list 10 min read HTML Tutorial HTML stands for HyperText Markup Language. It is the standard language used to create and structure content on the web. It tells the web browser how to display text, links, images, and other forms of multimedia on a webpage. HTML sets up the basic structure of a website, and then CSS and JavaScript 11 min read HTML Interview Questions and Answers HTML (HyperText Markup Language) is the foundational language for creating web pages and web applications. Whether you're a fresher or an experienced professional, preparing for an HTML interview requires a solid understanding of both basic and advanced concepts. Below is a curated list of 50+ HTML 14 min read Flask Tutorial Flask is a lightweight and powerful web framework for Python. Itâs often called a "micro-framework" because it provides the essentials for web development without unnecessary complexity. Unlike Django, which comes with built-in features like authentication and an admin panel, Flask keeps things mini 8 min read Pandas Tutorial Pandas is an open-source software library designed for data manipulation and analysis. It provides data structures like series and DataFrames to easily clean, transform and analyze large datasets and integrates with other Python libraries, such as NumPy and Matplotlib. It offers functions for data t 6 min read Top 10 Projects For Beginners To Practice HTML and CSS Skills Learning to code is an exciting journey, especially when stepping into the world of programming with HTML and CSSâthe foundation of every website you see today. For most beginners, these two building blocks are the perfect starting point to explore the creative side of web development, designing vis 8 min read HTML Introduction HTML stands for Hyper Text Markup Language, which is the core language used to structure content on the web. It organizes text, images, links, and media using tags and elements that browsers can interpret. As of 2025, over 95% of websites rely on HTML alongside CSS and JavaScript, making it a fundam 6 min read Adding New Column to Existing DataFrame in Pandas Adding a new column to a DataFrame in Pandas is a simple and common operation when working with data in Python. You can quickly create new columns by directly assigning values to them. Let's discuss how to add new columns to the existing DataFrame in Pandas. There can be multiple methods, based on d 6 min read HTML Tags - A to Z List HTML Tags are fundamental elements used to structure and format content on web pages. They provide instructions to web browsers on how to render text, images, links, and other media.HTML tags are enclosed in angle brackets < > and usually come in pairs: an opening tag and a closing tag. The cl 15+ min read Filter Pandas Dataframe by Column Value Filtering a Pandas DataFrame by column values is a common and essential task in data analysis. It allows to extract specific rows based on conditions applied to one or more columns, making it easier to work with relevant subsets of data. Let's start with a quick example to illustrate the concept:Pyt 7 min read Like