I am trying to parse out a column by the comma (also stripping the white space) and then pivoting all of the origin/destination combinations into new rows. Here is a sample of the data:
Origin     Destination     Weight
PVG        AMS, FRA        10,000
CAN, XMN   LAX, ORD        25,000
I am having trouble reproducing the dataframe above using pd.read_clipboard, so here is the dataframe code:
df = pd.DataFrame({'Origin': ['PVG', 'CAN, XMN'], 
                   'Destination': ['AMS, FRA', 'LAX, ORD'],
                   'Weight': [10000, 25000]})
The desired output would be:
Origin     Destination     Weight
PVG        AMS             10,000
PVG        FRA             10,000
CAN        LAX             25,000   
CAN        ORD             25,000
XMN        LAX             25,000
XMN        ORD             25,000   
I have been trying to use:
df['Origin'].str.split(',', expand = True)
I had tried doing this for both the origin and destination, which works for parsing the strings into separate columns. I am struggling to then create all of the possible combinations into separate rows (I have tried using pivot_table and melt with no luck).