Hello,
I have a collection of dataframes stored in a list of variable length [df1, df2]. How can I display both dataframes in my streamlit app?
Currently, I do:
for dataframe in [df1, df2]:
st.dataframe(dataframe)
this will only display one dataframe. How can I change my code in such a way that it shows all the dataframes from the list?
I am using Python 3.11.7 and Streamlit 1.30.0
Many thanks in advance!
Oscar1
2
Hi Talita_Anthonio
You can modify your code to loop through the list of dataframes and display each one individually
import streamlit as st
import pandas as pd
data1 = {'Nombre': ['Juan', 'María', 'Pedro'],
'Edad': [25, 30, 35],
'Ciudad': ['Madrid', 'Barcelona', 'Sevilla']}
df1 = pd.DataFrame(data1)
data2 = {'Producto': ['A', 'B', 'C'],
'Precio': [10, 20, 30],
'Cantidad': [100, 200, 300]}
df2 = pd.DataFrame(data2)
dataframes = [df1, df2]
for i, dataframe in enumerate(dataframes):
st.write(f"DataFrame {i+1}:")
st.dataframe(dataframe)