How to display tabular data using streamlit

In this recipe, we will learn how to display tabular data using Streamlit. We will also take a look at a simple Streamlit application consisting of tabular data.

Recipe Objective: How to display tabular data in streamlit?

To display a data frame as an interactive object you can use "st.dataframe()" whereas if you want to display static tables you can use "st.table()" to do so.

1) st.dataframe
 Syntax: st.dataframe(data, width, height)
 Parameters:
   data -> The data to display.
   width -> The desired width of the UI element in pixels. If None, then default width is used.
   height -> The desired height of the UI element in pixels. If None, then default height is used.

2) st.table
 Syntax: st.table(data)
 Parameters:
   data -> The data to display.

Code:

#importing required libraries
import streamlit as st
import pandas as pd
import numpy as np

#creating a sample dataframe
df = pd.DataFrame(
np.random.randn(7, 5),
columns=('col %d' % i for i in range(5)))

#displaying the dataframe in a static manner
st.table(df)

#displaying the dataframe as an interactive object
st.dataframe(df, 100, 200)

You can also change the style of the rendered dataframe by passing a Pandas Styler object as below

#highlighting maximum values in each column
st.dataframe(df.style.highlight_max(axis=0))

To run the app, either create an appname.py file with the above code using any text editor, or if you are using a jupyter notebook, you need to download your .ipynb notebook as a Python (.py) file and run the same using the "streamlit run appname.py" command. Once you run the command, the app will automatically open in your default browser.

What Users are saying..

profile image

Savvy Sahai

Data Science Intern, Capgemini
linkedin profile url

As a student looking to break into the field of data engineering and data science, one can get really confused as to which path to take. Very few ways to do it are Google, YouTube, etc. I was one of... Read More

Relevant Projects

Recommender System Machine Learning Project for Beginners-3
Content Based Recommender System Project - Building a Content-Based Product Recommender App with Streamlit

GCP MLOps Project to Deploy ARIMA Model using uWSGI Flask
Build an end-to-end MLOps Pipeline to deploy a Time Series ARIMA Model on GCP using uWSGI and Flask

Build a Graph Based Recommendation System in Python-Part 2
In this Graph Based Recommender System Project, you will build a recommender system project for eCommerce platforms and learn to use FAISS for efficient similarity search.

Hands-On Approach to Regression Discontinuity Design Python
In this machine learning project, you will learn to implement Regression Discontinuity Design Example in Python to determine the effect of age on Mortality Rate in Python.

Medical Image Segmentation Deep Learning Project
In this deep learning project, you will learn to implement Unet++ models for medical image segmentation to detect and classify colorectal polyps.

Recommender System Machine Learning Project for Beginners-2
Recommender System Machine Learning Project for Beginners Part 2- Learn how to build a recommender system for market basket analysis using association rule mining.

Hands-On Approach to Causal Inference in Machine Learning
In this Machine Learning Project, you will learn to implement various causal inference techniques in Python to determine, how effective the sprinkler is in making the grass wet.

Time Series Classification Project for Elevator Failure Prediction
In this Time Series Project, you will predict the failure of elevators using IoT sensor data as a time series classification machine learning problem.

Learn How to Build a Logistic Regression Model in PyTorch
In this Machine Learning Project, you will learn how to build a simple logistic regression model in PyTorch for customer churn prediction.

Learn to Build a Polynomial Regression Model from Scratch
In this Machine Learning Regression project, you will learn to build a polynomial regression model to predict points scored by the sports team.