0

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':

enter image description here

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:

enter image description here

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:

enter image description here

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

Ganesh Gebhard
  • 453
  • 1
  • 7
  • 20
  • you may need to convert this cell to a list, and them explode the cell in to new rows, and use your method. https://stackoverflow.com/questions/32468402/how-to-explode-a-list-inside-a-dataframe-cell-into-separate-rows https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.explode.html – Guinther Kovalski Aug 10 '21 at 19:20
  • This didn't work unfortunately. – Ganesh Gebhard Aug 11 '21 at 14:05

0 Answers0