How to join two columns (one is list other is integer id column ) in pandas python in one dataframe?

Question:

https://i.stack.imgur.com/ptVi1.png

enter image description here

I want to join these two columns in a new Dataframe like this:

enter image description here

Asked By: Faisal Fida

||

Answers:

join and explode:

out = (df_id.join(df_cast['Cast'].str.split(',s*'))
        .explode('Cast')
     )

Or explode and join:

out = df_id.join(df_cast['Cast'].str.split(',s*').explode('Cast'))
Answered By: mozway
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.