Sep-26-2023, 10:46 AM
Hi, as i`m new to python my code is not clean and not efficient and im looking towards faster performance while im loading my code.
Im using streamlit and pandas and i have filters like this 12 times for each filter option:
x with each option available
then to step up filtering i add 2 filter option so i filtrate by 2 options instead of 1
after that i add 3 option i can choose from my filter and 4 and 5 and all the way to the end that i can choose all filters and my data will be filtered [ Example: A or B or C or D or E or F or G or H or I or J or K or L- then AB or AC or AD or AE or EF , EG or AG ... or KBC ADB or ABCD or DEFGH or ABGHJI or GHIABCD etc. .... and end looks like ABCDEFGHIJKL if i choose all. ]
Currently i have 8 filters working in specific order[ have to choose A if i want C but if i choose C it wont show A and i choose filter H its not filtering out my filter G but if i choose filter G i can choose filter H ] and it takes 300 LOC and it takes ages to read when i start streamlit app ( not considering uploading file and filtering ).
Where i have to start to clean , minimize my code and make it more efficient while keeping my 12 filter options and maybe i can add more in the future.
Im not really sure with it but i think if i have 12 filters and i want to filter out by any selection i have 12x12x11 options ...give a take ?
Thank You.
Im using streamlit and pandas and i have filters like this 12 times for each filter option:
# Create for foo regionas = st.sidebar.multiselect("Pick your Regionas", options=df.sort_values(by="Regionas").Regionas.unique()) if not regionas: df2 = df.copy() else: df2 = df[df["Regionas"].isin(regionas)]
x with each option available
if not regionas and not valstija and not marketas and not zmogus and not daiktas and not dienos and not menesiai and not seima and not augintinis and not miestas and not siurprizas: filtered_df = df elif not valstija and not marketas and not zmogus and not daiktas and not dienos and not menesiai and not seima and not augintinis and not miestas and not siurprizas filtered_df = df[df["Regionas"].isin(regionas)]
then to step up filtering i add 2 filter option so i filtrate by 2 options instead of 1
elif valstija and regionas: filtered_df = df12[df["State"].isin(valstija) & df12["Regionas"].isin(regionas)]
after that i add 3 option i can choose from my filter and 4 and 5 and all the way to the end that i can choose all filters and my data will be filtered [ Example: A or B or C or D or E or F or G or H or I or J or K or L- then AB or AC or AD or AE or EF , EG or AG ... or KBC ADB or ABCD or DEFGH or ABGHJI or GHIABCD etc. .... and end looks like ABCDEFGHIJKL if i choose all. ]
Currently i have 8 filters working in specific order[ have to choose A if i want C but if i choose C it wont show A and i choose filter H its not filtering out my filter G but if i choose filter G i can choose filter H ] and it takes 300 LOC and it takes ages to read when i start streamlit app ( not considering uploading file and filtering ).
Where i have to start to clean , minimize my code and make it more efficient while keeping my 12 filter options and maybe i can add more in the future.
Im not really sure with it but i think if i have 12 filters and i want to filter out by any selection i have 12x12x11 options ...give a take ?
Thank You.