How to download a Pandas DataFrame as a CSV?

Use the st.download_button widget that is natively built into Streamlit. Check out a sample app demonstrating how you can use st.download_button to download common file formats.

import streamlit as st
import pandas as pd

df = pd.read_csv("dir/file.csv")

def convert_df(df):
   return df.to_csv(index=False).encode('utf-8')

csv = convert_df(df)

   "Press to Download",

Additional resources:


Still have questions?

Our forums are full of helpful information and Streamlit experts.

Was this page helpful?

editEdit this page on GitHub