My streamlit application has six dataframes. I want to have Streamlit download all dataframes in one excel file and get each dataframe a seperate sheet.
So for example;
df1 = excel sheet 1
df2 = excel sheet 2
So far I have only been succesful to download one df to excel. Could somebody help me out here?
This sounds like a pandas question. The function to read excel files in pandas has a parameter to specify the sheet for extraction. You can specify it by name (a string) or an index (an integer). If not specified, it defaults to 0, which means it reads in the first sheet. https://pandas.pydata.org/docs/reference/api/pandas.read_excel.html
There are a couple examples on StackExchange here:
streamlit not allowing to write multiple excel file at a time. i have seven dataframe in a file. when i ran on jupyter notebook i get seven sheets. When i ran this on streamlit it gave just one sheet
code:
for i, df in enumerate(finalname):
df.to_excel(w, sheet_name=fâsheet{i}')
w.save()
Please format your code properly and include code that defines all variables. finalname and w are undefined and the behavior depends on how you define them.
This code will save a workbook with seven sheets, no matter if you run it in a strealit app or not.
import pandas as pd
import streamlit as st
finalname = [pd.DataFrame()] * 7
with pd.ExcelWriter("df.xlsx") as w:
for i, df in enumerate(finalname):
df.to_excel(w, sheet_name=f"sheet{i}")
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking âAccept allâ, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.