I am using streamlit for displaying a dropdown menu based on a csv list (symbols.csv).
This is how the csv list looks:
This is the code I am writing:
JavaScript
x
14
14
1
def choosing_asset():
2
3
with open('symbols.csv', newline='') as f:
4
reader = csv.reader(f)
5
data = list(reader)
6
7
8
option = st.sidebar.selectbox('Select your asset',data)
9
10
name = option[0]
11
ticker = option[1]
12
13
return(name,ticker)
14
And this is how streamlit is displaying the dropdownmenu:
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
JavaScript
1
2
1
data = [ ['Bitcoin', 'BTC-USD'], ['Ethereum', 'ETH-USD'] ]
2
and you have to convert sublists to strings using ie. join
JavaScript
1
2
1
data = [','.join(row) for row in data]
2
Or you should read it as normal text file
JavaScript
1
4
1
with open('symbols.csv', newline='') as f:
2
data = list(f)
3
data = [line.strip() for line in data]
4
or
JavaScript
1
3
1
with open('symbols.csv', newline='') as f:
2
data = f.read().splitlines()
3
BTW:
And if you want to skip first row with Company_name,Company_ticker
JavaScript
1
2
1
data = data[1:]
2