I have a Pandas DataFrame with columns that contain data for some rows and not for others. I need to merge several columns into a single column, removing missing data. For example:
Name Preference_1 Preference_2 Preference_3 Preference_4
0 Dave Beach Lake Mountain Desert
1 Jeff Outdoors NaN NaN NaN
2 Tom Forest Ocean Swamp NaN
Needs to become this:
Name Preference
0 Dave Beach
1 Dave Lake
2 Dave Mountain
3 Dave Desert
4 Jeff Outdoors
5 Tom Ocean
6 Tom Swamp
7 Tom Forest
Ocean,Swampmove fromTomtoJeffin the output?