in [ ]mnames ['movie_id''title''genres'in [ ]movies pd read_table('ch /movies dat'sep='::'header=nonenames=mnamesin [ ]movies[: out[ ]movie_id title genres toy story ( animation|children' |comedy jumanji ( adventure|children' |fantasy grumpier old men ( comedy|romance waiting to exhale ( comedy|drama father of the bride part ii ( comedy heat ( action|crime|thriller sabrina ( comedy|romance tom and huck ( adventure|children' sudden death ( action goldeneye ( action|adventure|thriller adding indicator variables for each genre requires little bit of wrangling firstwe extract the list of unique genres in the dataset (using nice set union trick)in [ ]genre_iter (set( split('|')for in movies genresin [ ]genres sorted(set union(*genre_iter)nowone way to construct the indicator dataframe is to start with dataframe of all zerosin [ ]dummies dataframe(np zeros((len(movies)len(genres)))columns=genresnowiterate through each movie and set entries in each row of dummies to in [ ]for igen in enumerate(movies genres)dummies ix[igen split('|') thenas aboveyou can combine this with moviesin [ ]movies_windic movies join(dummies add_prefix('genre_')in [ ]movies_windic ix[ out[ ]movie_id title toy story ( genres animation|children' |comedy genre_action genre_adventure genre_animation genre_children' genre_comedy genre_crime genre_documentary genre_drama genre_fantasy data wranglingcleantransformmergereshape www it-ebooks info