title: Why does this not split the genres properly? (Python)
body: <p>I am trying to find the best-rated genres for this <a href="https://www.kaggle.com/isaactaylorofficial/imdb-10000-most-voted-feature-films-041118" rel="nofollow noreferrer">data set</a>. I started off splitting the genres because there were multiple genres in most rows. Then I sorted through the genres and their scores calculating the average score for each genre. I then update the data frame with each genre and their average score. However, there are repeating genres in the list for some reason and I'm not sure why.</p>
  <pre><code>dataGenre = data
  df5 = pd.DataFrame(data={&quot;Genre&quot;:dataYearScore['Genre'], &quot;Score&quot;: dataYearScore['Score']})
  df5 = df5.assign(Genre=df5['Genre'].str.split(',')).explode('Genre').reset_index(drop=True)
  
  genre_list5 = []
  avg_scores5 = []
  
  for genre in df5[&quot;Genre&quot;].unique():
      genre_list5.append(genre)
      avg_scores5.append(df5.loc[df5[&quot;Genre&quot;]==genre, &quot;Score&quot;].mean())
  
  plt.bar(genre_list5, avg_scores5, width = 0.8)
  plt.xlabel('Genre')
  plt.ylabel('Average Score')
  plt.xticks(rotation=65)
  plt.title('Average Score for Each Genre')
  plt.show()
  
  
  df5 = pd.DataFrame(data={&quot;Genre&quot;:genre_list5, &quot;Score&quot;: avg_scores5})
  df5
  </code></pre>
  <p>I believe the problem is either in line 3 or the for loop but I'm not sure whats doing it.
  Any help at all would be greatly appreciated :)</p>
  <p>Update:</p>
  <p>The data can be found here <a href="https://www.kaggle.com/isaactaylorofficial/imdb-10000-most-voted-feature-films-041118" rel="nofollow noreferrer">https://www.kaggle.com/isaactaylorofficial/imdb-10000-most-voted-feature-films-041118</a></p>
  <p>It's imported with</p>
  <pre><code>data = pd.read_csv('movies.csv')
  </code></pre>
  <p>I don't really need the graph, I just need the data frame to have a column with genres (no repeats) and their average score.</p>
  <pre><code>df5 = pd.DataFrame(data={&quot;Genre&quot;:genre_list5, &quot;Score&quot;: avg_scores5})
  df5
  </code></pre>
  <p>This is checked using the code above^</p>