title: List Index Out of Range error - pandas
body: <p>I have two data frames. df1 looks like - </p>
  
  <pre><code>MovieName    Actors
  lights out   Maria Bello
  legend       Tom Hardy*Emily Browning*Christopher Eccleston*David Thewlis
  </code></pre>
  
  <p>df2 looks like - </p>
  
  <pre><code>ActorName    Gender
  Tom          male
  Emily        female
  Christopher  male
  </code></pre>
  
  <p>I want to add two columns in df1 'female_actors' and 'male_actors' which contains the count of female and male actors in that particular movie respectively. Whether an actor is male or female is done based on df2. </p>
  
  <p>Here is what I am doing - </p>
  
  <pre><code>def func(actors, gender):
      actors = [act.split()[0] for act in actors.split('*')]      
      n_gender = df2.Gender[df2.Gender==gender][df2.ActorName.isin(actors)].count()
      return n_gender
  
  df1['male_actors'] = df1.Actors.apply(lambda x: func(x, 'male'))
  df1['female_actors'] = df1.Actors.apply(lambda x: func(x, 'female'))
  </code></pre>
  
  <p><strong>This code gives me list index out of range error.</strong></p>
  
  <p>Please note that -</p>
  
  <p>If particular name isn't present in gender.csv, don't count it in the total.
  If there is just one actor in a movie, and it isn't present in gender.csv, then it's count should be zero.</p>
  
  <p>Result should be - </p>
  
  <pre><code>MovieName    Actors      male_actors    female_actors
  lights out   Maria Bello    0              0
  legend       Tom Hardy*Emily Browning*Christopher Eccleston*David Thewlis    2    1
  </code></pre>
  
  <p>Feel free to suggest some other approach.</p>