Separating categories within one column in my dataframe
问题 I need to research something about what are the most cost efficient movie genres. My problem is that the genres are provided all within one string: This gives me about 300 different unique categories. How can I split these into about 12 original dummy genre columns so I can analyse each main genre? 回答1: Thanks to Yong Wang who suggested the get_dummies function within pandas. We can shorten the code significantly: df = pd.DataFrame({ 'movie_id': range(5), 'gernes': [ 'Action|Adventure|Fantasy