Skip to content
Advertisement

Dropdownmenu in Streamlit without brackets and quotes

I am using streamlit for displaying a dropdown menu based on a csv list (symbols.csv).

This is how the csv list looks:

enter image description here

This is the code I am writing:

def choosing_asset():

with open('symbols.csv', newline='') as f:
    reader = csv.reader(f)
    data = list(reader)


option = st.sidebar.selectbox('Select your asset',data)

name = option[0]
ticker = option[1]

return(name,ticker)

And this is how streamlit is displaying the dropdownmenu:

enter image description here

I would like to remove those brackets and quotes from the dropdownmenu, I would like to show only in the format “Bitcoin, BTC-USD” like in the csv file.

Thanks in advance

Advertisement

Answer

You have nested list like this

data = [ ['Bitcoin', 'BTC-USD'], ['Ethereum', 'ETH-USD'] ]

and you have to convert sublists to strings using ie. join

data = [','.join(row) for row in data]

Or you should read it as normal text file

with open('symbols.csv', newline='') as f:
    data = list(f)
    data = [line.strip() for line in data]

or

with open('symbols.csv', newline='') as f:
    data = f.read().splitlines()

BTW:

And if you want to skip first row with Company_name,Company_ticker

data = data[1:]
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement