I have a pandas dataframe df
df = pd.DataFrame(np.array([[0.6, 0.4, 0], [0.0, 1.0, 0], [0.4, 0.6, 0]]),columns = [-5, 0, 5])
print(df)
-5 0 5
0 0.6 0.4 0.0
1 0.0 1.0 0.0
2 0.4 0.6 0.0
I want to find name of columns with non-zero row values. The columns names of non-zero value in each row should be stored in a list. For example following is the expected outcome for three row in df
Expected outcome:
[[-5,0],[0],[-5,0]]