Print column and row name of cell if cell in table is greater than 0 using python pandas

0

I am having trouble to retrive name of column and row of cell in a table

my scenario is- if any element in my table is greater than 0 then print its column and rows

example i have attached a photo of my table i need to print date and slot time of cell if any cell is greater than 0

response i would expect is below from table i attached

08-05-2022 , SLOT1(07.30-08.00)  
08-05-2022 , SLOT2(11.00-11.30)
08-05-2022 , SLOT3(14.00-14.30)
08-05-2022 , SLOT4(15.00-15.30)
09-05-2022 , SLOT1(07.30-08.00)
09-05-2022 , SLOT4(15.00-15.30)
10-05-2022 , SLOT3(14.00-14.30)
11-05-2022 , SLOT2(11.00-11.30)

below is code used by me to filter columns having cell greater than 0 from a big table image i attached is filtered using below code i cannot find any code to solve my issue i described above

filtered = df.loc[df['SLOT1 (07.30-08.00)'] != 0]
print (filtered)
filtered2 = filtered2.loc[df['SLOT2 (11.00-11.30)'] != 0]
print(filtered2)

What output are you getting?
Sounds like it’s not the one you expect, but it would help if you actually shared it. Because I have trouble understanding your problem. Code seems fine to me, thus I’d need more information to understand where you have a problem.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.