I\'m fairly new to python and working with a DataFrame in pandas & numpy from Th
ID: 3911501 • Letter: I
Question
I'm fairly new to python and working with a DataFrame in pandas & numpy from The Movie Database. One of the columns notes the main cast of each movie separated by the pipe symbol (|). I'm trying to find a way to split each individual cast member and list it in its own row with the movie title. I've attached a snippet below of the results I get.
original title cast Jurassic World Chris Pratt Bryce Dallas Howardlrrfan KhanlVi... .. Insurgent Shailene Woodley Theo James Kate Winslet/Anse... 3 Star Wars: The Force Awakens Harrison Ford Mark Hamill Carrie Fisher Adam D... 0 Mad Max: Fury Road Tom Hardy Charlize Theron Hugh Keays-ByrnelNic 2 4 Furious 7 Vin Diesel Paul Walker|Jason Statham MichelleExplanation / Answer
Hello i tried created a dataframe by myself and able to achieve the output you are expecting.
I used Stack to achieve this, but there maybe some better approaches you can explore.
What Stack does is it reshapes the Dataframe or series and make the column is stacked rowwise. What Unstack does is vice versa.
Below is the working code:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.