I have the following dataframe which has a unique URL in the first column, followed by a random number of unique keywords. I would like to transpose the keywords into a single row and forward fill the url as per my desired output below.
0 1 2 3 4 5
www.example.com/page1 car dog cat bat apple
www.example.com/page2 dog car
www.example.com/page3 cat bat apple
Desired Output:
0 1 2 3 4 5
www.example.com/page1 car
www.example.com/page1 dog
www.example.com/page1 cat
www.example.com/page1 bat
www.example.com/page1 apple
www.example.com/page2 dog
www.example.com/page2 car
www.example.com/page3 cat
www.example.com/page3 bat
www.example.com/page3 apple
what I've tried: I've looked at these solutiosn, but neither seem to work for me. I've also consulted the docs on pd.melt but could not get it to work. (Still learning. Any help appreciated). Pandas create new date rows and forward fill column values Converting rows to columns using UNPIVOT