title: How to search and get count of special characters for every unique item in pandas
body: <p>By using pandas dataframe, I am trying to get count of special chars in column using but not getting desired output.</p>
  
  <p>My .tsv file is:<a href="https://i.stack.imgur.com/KOw7H.png" rel="nofollow noreferrer">input file</a></p>
  
  <pre><code>NAME        ID
  S. gambu    NNNTYR
  S. gambu    RTD:78689
  S. gambu    GTT:67878
  S. gambu    RTD?78689
  G. homos    SFDG\SS234R
  G. homos    SFHG#SR234R
  G. homos    JHFG:EE345T
  G. homos    TYU=TT678R
  T. mosus    RTU,YY67ET
  T. mosus    TTR%YY67ET
  G. ytrty    NaN
  </code></pre>
  
  <p>I am trying to get count for every special characters (:\,#%=?) form 'ID' w.r.t 'NAME' (for every name)(name =4 and special characters = 7) , I am not getting an desired output for every name and special characters present in ID's which are "(:\,#%=?)"</p>
  
  <p>i need count for every special characters for every name. 
  i tried, but not getting following desired output.</p>
  
  <p>Desired output is: </p>
  
  <pre><code>NAME         :        \          #       ?         %           =          ,
  
  S. gambu  RTD:78689    0         0    RTD?78689    0          0          0        
             GTT:67878                      
             count(2)                    count(1)                                
  
  
  
  G. homos     0   SFDG\SS234R  SFHG#SR234R    0       0       TYU=TT678R     0
                    count(1)     count(1)                       count(1)
  
  T. mosus     0       0          0         0    TTR%YY67ET      0    RTU,YY67ET          
                                               count(1)                 count(1)
  
  G. ytrty     NaN    NaN         NaN     NaN      NaN           NaN      NaN  
  
  
  Total         2      1           1       1          1            1            1
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Q5WYP.png" rel="nofollow noreferrer">desired output</a></p>
  
  <p>~ ~ ~ python<br>
  code i tried:</p>
  
  <pre><code>pattern1 = [':','#',',','%',]
  count= 0
  count1 = 0
  with open('name.txt') as f:
  lines = f.read().splitlines()
  
  
  for pat in pattern1:
      pattern1 = re.compile(pat)
       for line in lines:
          for i in range(len(df3)):
                  if ((df3.loc[i,'NAME'] == line)):
                      if (pattern1.search(df3.loc[i,'ID'])):
                          count = count+1
                      out =str(df3.loc[i,'NAME'])+"\t"+str(df3.loc[i,'ID'])+"\n"
                      print(out)
  </code></pre>
  
  <p>~ ~ ~  </p>
  
  <p>for desired output i have attached snap since out it contained more fields.</p>