I am not overly familiar with pandas so this may be a dumb question. I was trying to pivot the following data:
df = pd.DataFrame({
'Country' : ['country1', 'country2', 'country3', 'country4'],
'Industry' : ['industry1:\$20 \n industry4:\$30',
'industry10:\$100',
'industry3:\$2 \n industry4:\$30 \n industry12:\$10 \n industry1:\$3',
'industry1:\$20 \n industry4:\$30'
],})
(the \n come from an excel extraction)
I need to pivot to have the industries as indices and countries as columns. My intuition is that I need to do some kind of "data unpacking" first on the cells that contain multiple information but I am at a loss at how to do it on pandas.
Thanks all. There are some answers below that work well. I continued to search and found some other posts related to this issue (some people call this issue "exploding pandas rows"). In the thread below, someone wrote a general function explode() that is generic and performs well:
Split (explode) pandas dataframe string entry to separate rows