I couldn't find this anywhere, so I hope someone can help me.
I have a window written with tkinter, which contains an OptionMenu. The OptionMenu consists of the numbers 1 to 4 and the option 'all':
Now this OptionMenu is used as a filter for a dataframe and here comes the problem right a away. Before, I simply used the following code to filter the dataframe:
value_term = ['3']
df_filtered= df[(df['Term'].astype(str).isin(value_term))]
Which works when there is only one number in each dataframe cell:
The option 'all' works because I used this code:
value_term = ['1', '2', '3', '4']
Which enables me to not filter the dataframe. Now the problem is that there is a new situation, which cannot be handled by this:
As you can see, this cell contains two number separated by a semicolon. I tried using this code:
df_filtered= df[(df['Term'].astype(str).str.contains(value_term))]
Which works for when the input is one number (as string), but I have no idea how to make sure that the list is not filtered when the user chooses 'all'. The closest option would be: use an if-statement, but the code that I just showed has only one filter while the real code has more:
df_filtered= df[(df['Mandatory'].str.contains(value_track))
& (df['Term'].astype(str).isin(value_term))
& (df['Points'].astype(str).isin(value_ECTS))
& (df['Type'].isin(value_type))
& (df['TP'].isin(value_tech_ppd))
& (df['Theme'].isin(value_theme))]
Does someone know how to do this?
Best, Ganesh