Display 3 expanders beside each others using columns


how to display expanders beside each other using st.columns where i need to display 3 expanders on each row.

Steps to reproduce

Code snippet:

add code here

cols = st.columns(len(df))

for i ,x in enumerate(cols):
     with st.expander(f"{df[i]['name']}"): 

the expected result is to display each 3 expanders besides each others
i tried to change the value of cols to 3 but it did not return what i expected it just limit the display into only 3 records or expanders and they are above each other not beside

Hi @leb_dev

Here you go:

import streamlit as st
import pandas as pd

df=pd.DataFrame({ "name": ['Erica', 'Rogers', 'Malcolm', 'Barrett'], "jobno": [43, 35, 57, 29]})
cols = st.columns(len(df))

for i, x in enumerate(cols):
    with cols[i].expander(df.loc[i, 'name'], False):
        st.write(df.loc[i, 'jobno'])


i tried the answer it display expanders beside each others but i want to limit the display on each row up to 3 so if len(df) = 6
it must display first 3 on the first row than the other 3 on the secodn row and so on .

Hi @leb_dev

You already have a for loop for columns. You just have to precede it with a for loop for rows and initialize your columns therein.

Give it a try.