Question: Python and Pandas The DataFrame: I created an array of all of the unique genres: I need to add on to movie dataframe with a

Python and Pandas

Python and Pandas The DataFrame: I created an array of all of

The DataFrame:

the unique genres: I need to add on to movie dataframe with

I created an array of all of the unique genres:

a column for each uniqueGenre and if it appears in genres for

I need to add on to movie dataframe with a column for each uniqueGenre and if it appears in genres for that row, it needs to be True and if it doesn't appear in genres for that row, it needs to be False.

Keep in mind that the column genres has multiple values.

I can do this if the column genres has one value but I need to know how to do it when the column genres has multiple values.

Q 4 (1 point) build columns for different genres with value True or False based on whether a genre is present or not in an observation? movield title genres 0 1 Toy Story (1995) Adventure|Animation|Children Comedy|Fantasy 1 2 Jumanji (1995) Adventure Children Fantasy 2 3 Grumpier Old Men (1995) Comedy Romance 3 4 Waiting to Exhale (1995) Comedy Drama Romance 4 5 Father of the Bride Part II (1995) Comedy II. 9737 193581 Black Butler: Book of the Atlantic (2017) Action|Animation Comedy Fantasy 9738 193583 No Game No Life: Zero (2017) Animation Comedy Fantasy 9739 193585 Flint (2017) Drama 9740 193587 Bungo Stray Dogs: Dead Apple (2018) Action Animation 9741 193609 Andrew Dice Clay: Dice Rules (1991) Comedy 9742 rows x 3 columns 1 # write pandas code here 2 unique_genres pd.unique (movie["genres").str.split("|", expand=True).stack()) 3 unique_genres array( ['Adventure', 'Animation', 'Children', 'Comedy', 'Fantasy', 'Romance', 'Drama', 'Action', 'Crime', 'Thriller', 'Horror', "Mystery', 'Sci-Fi', 'War', Musical', 'Documentary', 'IMAX", 'Western', 'Film-Noir', '(no genres listed)'], dtype=object)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!