title: Searching with Panda based on specific categorization in Python
body: <p>Dears,
  I have a csv file with below content, There are several Teams with members and Team, Now I want to select a captain and the another person who is the replace of Captian in an NBA Basketball team.</p>
  <p>Different team exists, so I categorized them to TEAMA, TEAMB,TEAMC.</p>
  <pre><code>SiteCode          Name    Type      NO
  TEAMA       Al Horford      A       20
  TEAMA       Tiago Splitter  B       19
  TEAMA       Walter Tavares  C       18
  TEAMA       Kris Humphries  D       17
  TEAMA       Paul Millsap    E       16
  TEAMB       Mike Muscala    A       20
  TEAMB       Mike Scott      B       20
  TEAMB       Dennis Schroder C       18
  TEAMC       Jeff Teague     A       20
  TEAMC       Kent Bazemore   B       19
  </code></pre>
  <ol>
  <li>If Type=A Captian is A, If B exists A will be Captian of B and If Any other members exist B will be the Captian of any other member:
  I should add No of Captian and ReplaceCaptian to other columns, I don't know how to search based on team and find the NO of Captian and put it in CaptianNo fields.
  (I think I should go ahead and solve this by adding a for loop and search based on team.)</li>
  </ol>
  <p>Code:</p>
  <pre><code>    import pandas as pd
      import numpy as np
      df = pd.read_csv(&quot;C:\\Users\\Desktop\\P.csv&quot;)
      df[&quot;Captian&quot;] = [&quot;A&quot; if x==&quot;A&quot; or x==&quot;B&quot; else &quot;B&quot; for x in df[&quot;Type&quot;]]
      df[&quot;CaptianNO&quot;] = [&quot;A&quot; if x==&quot;A&quot; or x==&quot;B&quot; else &quot;A&quot; for x in df[&quot;NO&quot;]]
      df[&quot;ReplaceCaptain&quot;] = [&quot;A&quot; if x==&quot;A&quot; else x for x in df[&quot;Type&quot;]]
      df[&quot;ReplaceCaptainNO&quot;] = [&quot;A&quot; if x==&quot;A&quot; else x for x in df[&quot;NO&quot;]]
      print(df)
      df.head(3)
      df.to_csv('C:\\Users\\Desktop\\Captian.csv')
  </code></pre>
  <p>Actual Result of code which CatianNO is A and not the NO value it's relative Captian .</p>
  <pre><code>ID  SiteCode    Name        Type    NO  Captian CaptianNO   ReplaceCaptain  ReplaceCaptainNO
  0   TEAMA   Al Horford      A       20     A        A                A                20
  1   TEAMA   Tiago Splitter  B       19     A        A                B                19
  2   TEAMA   Walter Tavares  C       18     B        A                C                18
  3   TEAMA   Kris Humphries  D       17     B        A                D                17
  4   TEAMA   Paul Millsap    E       16     B        A                E                16
  5   TEAMB   Mike Muscala    A       20     A        A                A                20
  6   TEAMB   Mike Scott      B       19     A        A                B                19
  7   TEAMB   Dennis Schroder C       18     B        A                C                18
  8   TEAMA   Jeff Teague     A       20     A        A                A                20
  9   TEAMA   Kent Bazemore   B       19     A        A                B                19
  </code></pre>
  <p>Expected Result:</p>
  <pre><code>ID  SiteCode    Name       Type NO  Captian CaptianNO   ReplaceCaptain  ReplaceCaptainNO
  0   TEAMA   Al Horford      A   20      A       20              A               20
  1   TEAMA   Tiago Splitter  B   19      A       20              B               19
  2   TEAMA   Walter Tavares  C   18      B       19              C               18
  3   TEAMA   Kris Humphries  D   17      B       19              D               17
  4   TEAMA   Paul Millsap    E   16      B       19              E               16
  5   TEAMB   Mike Muscala    A   20      A       20              A               20
  6   TEAMB   Mike Scott      B   19      A       20              B               20
  7   TEAMB   Dennis Schroder C   18      B       19              C               18
  8   TEAMA   Jeff Teague     A   20      A       20              A               20
  9   TEAMA   Kent Bazemore   B   19      A       20              B               19
  </code></pre>