title: pandas create new column based on values from other columns / apply a function of multiple columns, row-wise
body: <p>I want to apply my custom function (it uses an if-else ladder) to these six columns (<code>ERI_Hispanic</code>, <code>ERI_AmerInd_AKNatv</code>, <code>ERI_Asian</code>, <code>ERI_Black_Afr.Amer</code>, <code>ERI_HI_PacIsl</code>, <code>ERI_White</code>) in each row of my dataframe.</p>
  <p>I've tried different methods from other questions but still can't seem to find the right answer for my problem.  The critical piece of this is that if the person is counted as Hispanic they can't be counted as anything else.  Even if they have a &quot;1&quot; in another ethnicity column they still are counted as Hispanic not two or more races.  Similarly, if the sum of all the ERI columns is greater than 1 they are counted as two or more races and can't be counted as a unique ethnicity(except for Hispanic).</p>
  <p>It's almost like doing a for loop through each row and if each record meets a criterion they are added to one list and eliminated from the original.</p>
  <p>From the dataframe below I need to calculate a new column based on the following spec in SQL:</p>
  <p><strong>CRITERIA</strong></p>
  <pre><code>IF [ERI_Hispanic] = 1 THEN RETURN “Hispanic”
  ELSE IF SUM([ERI_AmerInd_AKNatv] + [ERI_Asian] + [ERI_Black_Afr.Amer] + [ERI_HI_PacIsl] + [ERI_White]) &gt; 1 THEN RETURN “Two or More”
  ELSE IF [ERI_AmerInd_AKNatv] = 1 THEN RETURN “A/I AK Native”
  ELSE IF [ERI_Asian] = 1 THEN RETURN “Asian”
  ELSE IF [ERI_Black_Afr.Amer] = 1 THEN RETURN “Black/AA”
  ELSE IF [ERI_HI_PacIsl] = 1 THEN RETURN “Haw/Pac Isl.”
  ELSE IF [ERI_White] = 1 THEN RETURN “White”
  </code></pre>
  <p>Comment: If the ERI Flag for Hispanic is True (1), the employee is classified as “Hispanic”</p>
  <p>Comment: If more than 1 non-Hispanic ERI Flag is true, return “Two or More”</p>
  <p><strong>DATAFRAME</strong></p>
  <pre><code>     lname          fname       rno_cd  eri_afr_amer    eri_asian   eri_hawaiian    eri_hispanic    eri_nat_amer    eri_white   rno_defined
  0    MOST           JEFF        E       0               0           0               0               0               1           White
  1    CRUISE         TOM         E       0               0           0               1               0               0           White
  2    DEPP           JOHNNY              0               0           0               0               0               1           Unknown
  3    DICAP          LEO                 0               0           0               0               0               1           Unknown
  4    BRANDO         MARLON      E       0               0           0               0               0               0           White
  5    HANKS          TOM         0                       0           0               0               0               1           Unknown
  6    DENIRO         ROBERT      E       0               1           0               0               0               1           White
  7    PACINO         AL          E       0               0           0               0               0               1           White
  8    WILLIAMS       ROBIN       E       0               0           1               0               0               0           White
  9    EASTWOOD       CLINT       E       0               0           0               0               0               1           White
  </code></pre>