I'm new in Python and Pandas.
I'm trying to filter a string dataframe by two conditions, to get a list or dataframe with indexs and columns that satisfy both conditions. I get this dataframe from a spreadsheet where each cell is YES or NOT.
df = pd.DataFrame([['YES', 'YES', 'NO', 'NO'], ['NO', 'YES', 'NO', 'NO'], ['NO', 'NO', 'NO', 'NO'], ['YES', 'NO', 'NO', 'YES']],
index=['task1', 'task2', 'task3', 'task4'],
columns=['David', 'Carol', 'Tony', 'Anna'])
df
David Carol Tony Anna
taks1 YES YES NO NO
task2 NO YES NO NO
task3 NO NO NO NO
task4 YES NO NO YES
I need to get something like this (two lists, dataframe, bidimensional array...):
David task1
David task4
Carol task1
Carol task2
Anna task4
I have used loc, but I cannot extend the filter for all the columns:
active = df.loc[lambda df1: df1['David'] == 'YES', :]
Rows and columns number are unknown when I read spreadsheet, therefore, I need to have a flexible solution for different tables size.