I got a dataframe which looks like
Fever Chill Cough Headache Respiratory Nasal Joint Pain Back pain Stomach pain
0 Y Y Y NaN NaN NaN NaN NaN NaN
1 Y NaN NaN NaN Y NaN NaN NaN NaN
2 Y NaN Y NaN NaN NaN NaN NaN NaN
3 Y NaN NaN NaN NaN NaN Y NaN NaN
4 Y NaN NaN NaN NaN NaN NaN NaN NaN
I want to convert columns header into single column (let say symptom) in such a way that newly column contains the column header name when it has value Y. Desired column should be look like:
Symptom
0 Fever, Chill, Cough
1 Fever, Respiratory
2 Fever, Cough
3 Fever, Joint Pain
4 Fever
I used the concept of stack, but it didnt produce the desired ouput. Here is my code:
df[['Fever','Chill','Cough','Headache','Respiratory symptom','Nasal Symptoms','Joint Pain','Back pain','Stomach pain','Diarrhoea','Vomiting','Fatigue','Pneumonia shadow']].stack().reset_index()
Could anyone guide me how to get the desired result?