Converting Pandas dataframe

I have a dataframe as below

before_df

I would like to convert it into the following dataframe

after_df

how can i do this?

Edit 1: I figured out how to do this. Pandas has a stack function which can do this function. Also check out pivot.

Would you be able to post the code solution you used to fix this for future people that may have this same type of situation?

Sure :smiley:

Try this :

stacked = df.stack()
stacked = stacked.to_frame()
stacked = stacked.reset_index()
stacked= stacked.drop(['level_0'], axis = 1)