List.remove() doesn't behave as expected

Hello there! I was trying to get the list of column names in my data frame for my selectbox, and I need the date column to be removed from it (the list of column names is [“date”, “name1”, “name2”, etc]). So I assigned the new variable for this and used list.remove() to get rid of “date”. However, when I launch the app it shows the list not as [“name1”, “name2”, “name3”, etc], but as [“name1”, “name1.1”, “name2”, “name3”, etc]. Any ways how to do it correctly? What is the source or this misbehavior?

Code snippet:

df = load_data()
assets_list = df.columns.tolist()
assets_list.remove("date")


option = st.sidebar.selectbox("Select an asset", assets_list)
st.write("you selected", option)

initial data set for assets_list: [“date”, “name1”, “name2”, “name3”, etc]
Expected behavior:

[“name1”, “name2”, “name3”, etc] list

Actual behavior:

[“name1”, “name1.1”, “name2”, “name3”, etc] list

Debug info

  • Streamlit version: 1.18.1
  • Python version: 3.9.13

Try my example code below. That example works just fine from my test.

import streamlit as st
import pandas as pd


data = {
    'date': ['2023-02-12', '2023-02-13'],
    'name1': ['aaa', 'bbb'],
    'name2': ['ccc', 'ddd'],
    'name3': ['eee', 'fff']
}


df = pd.DataFrame(data)

assets_list = df.columns.tolist()
assets_list.remove("date")

option = st.sidebar.selectbox("Select an asset", assets_list)
st.write("you selected", option)
1 Like

Thank you for your reply. Indeed I haven’t thought about the simple test. lloks like streamlit is working correctly within the test dataframe. I’ll try to find the source of the problem within the dataframe or somewhere else.