ProCodebaseProCodebase
  • ModusA Growth OS for your business, on WhatsAppKiosqSell more. Chase less.AI InterviewerAutomated screening & AI-led interviewsXperto AIAI prep companion for candidatesAI Tools HubResume builder, learning paths & more
  • Pre-Vetted DevelopersScreened, scored and ready to interviewAI-Native DevelopersSenior engineers on an hourly basis
  • Services
  • Features
  • Jobs
  • FAQs
Sign inBook a demo
  • Services
  • Features
  • Jobs
  • FAQs
Sign inBook a demo
ProCodebaseProCodebase

ProCodebase Technologies builds AI products for hiring and growth, and ships software for clients as a technical consultancy. We source, screen and deliver pre-vetted developers — so you only interview high-signal candidates.

Products

  • Modus
  • Kiosq
  • AI Interviewer
  • Xperto AI
  • AI Tools Hub

Hire & build

  • Pre-Vetted Developers
  • AI-Native Developers
  • Technical Consultancy
  • MVP Development
  • Features

Resources

  • Articles
  • Topics
  • Certifications
  • Collections
  • Jobs

Company

  • About Us
  • Contact Us
  • Book a Demo
  • FAQs

© 2026 ProCodebase Technologies. All rights reserved.

  • Privacy Policy
  • Terms & Conditions
  • Refund & Cancellation

Level Up Your Skills with Xperto-AI

A multi-AI agent platform that helps you level up your development skills and ace your interview preparation to secure your dream job.

Launch Xperto-AI

Harnessing Streamlit for Dynamic DataFrames and Tables in Python

author
Generated by
ProCodebase AI

15/11/2024

python

Sign in to read full article

Introduction to Streamlit for Data Display

Streamlit is a powerful Python library that makes it incredibly easy to create interactive web applications for data science and machine learning projects. One of its standout features is the ability to display and manipulate DataFrames and tables with minimal code. In this blog post, we'll explore how to leverage Streamlit to present your data effectively.

Basic DataFrame Display

Let's start with the basics. Displaying a DataFrame in Streamlit is as simple as using the st.dataframe() function. Here's a quick example:

import streamlit as st import pandas as pd # Create a sample DataFrame df = pd.DataFrame({ 'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [25, 30, 35], 'City': ['New York', 'San Francisco', 'London'] }) # Display the DataFrame st.dataframe(df)

This code will render a simple, interactive table in your Streamlit app. Users can sort columns and scroll if the DataFrame is large.

Customizing DataFrame Appearance

Streamlit allows you to customize the appearance of your DataFrames. You can set the width and height, highlight specific values, and more. Here's an example:

st.dataframe(df.style.highlight_max(axis=0), width=700, height=300)

This will display the DataFrame with the maximum value in each column highlighted, and set a specific width and height for the table.

Using st.table() for Static Tables

While st.dataframe() creates an interactive table, sometimes you might want a static view. That's where st.table() comes in handy:

st.table(df)

This creates a static table that fits the width of the container and doesn't have interactive features like sorting or scrolling.

Advanced DataFrame Interactions

Streamlit offers more advanced features for working with DataFrames. Let's explore a few:

Editable DataFrames

You can create editable DataFrames using the st.data_editor() function:

edited_df = st.data_editor(df)

This allows users to modify the data directly in the app. The edited DataFrame is returned, which you can then use for further processing.

Conditional Formatting

You can apply conditional formatting to highlight specific data points:

st.dataframe(df.style.applymap(lambda x: 'color: red' if x > 30 else 'color: black', subset=['Age']))

This will color any age value over 30 in red.

Column Configuration

Streamlit allows you to configure individual columns in your DataFrame display:

st.dataframe(df, column_config={ "Name": st.column_config.TextColumn( "Full Name", help="The person's full name", max_chars=50, ), "Age": st.column_config.NumberColumn( "Age (years)", help="The person's age", min_value=0, max_value=120, step=1, ), "City": st.column_config.SelectboxColumn( "Current City", help="The city where the person lives", width="medium", options=[ "New York", "San Francisco", "London", "Tokyo", "Berlin" ], ) })

This configuration adds help text, sets input types, and provides a dropdown for the City column.

Pagination for Large DataFrames

When dealing with large DataFrames, pagination can improve performance and user experience:

import math # Assume 'large_df' is your large DataFrame items_per_page = 10 pages = math.ceil(len(large_df) / items_per_page) page = st.selectbox('Page', range(1, pages + 1)) start_idx = (page - 1) * items_per_page end_idx = start_idx + items_per_page st.dataframe(large_df.iloc[start_idx:end_idx])

This code creates a paginated view of your large DataFrame, allowing users to navigate through pages easily.

Conclusion

Streamlit provides a rich set of tools for working with DataFrames and tables in Python. From basic displays to advanced interactions, you can create engaging and informative data presentations with just a few lines of code. As you continue to explore Streamlit, you'll discover even more ways to enhance your data visualization and create powerful, interactive web applications.

Popular tags

pythonstreamlitdataframes

Share now!

Like & bookmark

Related collections

  • Mastering LangGraph: Stateful, Orchestration Framework

    17/11/2024 · Python

  • Python Basics: Comprehensive Guide

    21/09/2024 · Python

  • Python with Redis Cache

    08/11/2024 · Python

  • Mastering NLTK for Natural Language Processing

    22/11/2024 · Python

  • Mastering Pandas: From Foundations to Advanced Data Engineering

    25/09/2024 · Python

Related articles

  • Mastering Response Models and Status Codes in FastAPI

    15/10/2024 · Python

  • Query Parameters and Request Body in FastAPI

    15/10/2024 · Python

  • Regression Plots

    06/10/2024 · Python

  • Mastering NumPy Broadcasting

    25/09/2024 · Python

  • Unlocking the Power of Advanced Query Transformations in LlamaIndex

    05/11/2024 · Python

  • Maximizing Efficiency

    05/11/2024 · Python

  • Creating Your First Plot with Matplotlib

    05/10/2024 · Python

Popular category

  • Python
  • Generative AI
  • Machine Learning
  • ReactJS
  • System Design