0

I'm trying to explode the genres column into a separate data frame with (id, name) as columns.

this is the data frame I'm working with enter image description here

this is what I'm trying to achieve enter image description here

i havent been able to find a solution on my own what i have tried is to explode the genre

genres = df['genres'].explode()

1
  • Try genres = pd.DataFrame(df.genres.explode().values.tolist()) Commented Jan 4, 2023 at 21:46

1 Answer 1

1

You can use pandas.Series.explode with pandas.DataFrame constructor :

#if need to evalute the column as lists of dict
#from ast import literal_eval
#df["genres"] = df["genres"].apply(literal_eval)

genres = pd.DataFrame(df.pop("genres").explode().tolist())
         
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.