I have a dataframe of the form:
basket fruit_apple fruit_pear fruit_cherry
basket_id_1 5 NaN 6
basket_id_2 NaN 1 NaN
and I want to create two new columns that should look like this:
basket fruit_type number
basket_id_1 apple 5
basket_id_1 pear NaN
basket_id_1 cherry 6
basket_id_2 apple NaN
basket_id_2 pear 1
basket_id_2 cherry NaN
where the contents of fruit_type are determined automatically with a colname.split('_')[1]
How can this be done in a concise way?