title: Python pandas how to scan string contains by row?
body: <p>How do you scan if a pandas dataframe row contains a certain substring?</p>
  
  <p>for example i have a dataframe with 11 columns 
  all the columns contains names</p>
  
  <pre><code>ID    name1     name2       name3      ...    name10
  -------------------------------------------------------
  AA    AA_balls  AA_cakee1  AA_lavender ...   AA_purple
  AD    AD_cakee  AD_cats    AD_webss    ...   AD_ballss
  CS    CS_cakee  CS_cats    CS_webss    ...   CS_purble
  .
  .
  .
  </code></pre>
  
  <p>I would like to get rows which contains, say "ball" in the dataframe and get the ID</p>
  
  <p>so the result would be ID 'AA' and ID 'AD' since AA_balls and AD_ballss are in the rows.</p>
  
  <p>I have searched on google but seems there is no specific result for these.
  people usually ask questions about searching substring in a specific columns but not all columns (a single row)</p>
  
  <pre><code>df[df["col_name"].str.contains("ball")]
  </code></pre>
  
  <hr>
  
  <p>The Methods I have thought of are as follows, you can skip this if you have little time:</p>
  
  <p>(1) loop through the columns</p>
  
  <pre><code>for col_name in col_names:
       df.append(df[df[col_name].str.contains('ball')])
  </code></pre>
  
  <p>and then drop duplicates rows which have same ID values
  but this method would be very slow</p>
  
  <p>(2) Make data frame to a 2 column dataframe by appending name2- name10 columns into one column and use df[df["concat_col"].str.contains("ball")]["ID] to get the IDs and drop duplicate</p>
  
  <pre><code>ID  concat_col   
  AA    AA_balls 
  AA    AA_cakeee
  AA    AA_lavender
  AA    AA_purple
   .
   .
   .
  CS   CS_purble
  </code></pre>
  
  <p>(3) Use the dataframe like (2) to make a dictionay
  where</p>
  
  <pre><code> dict[df["concat_col"].value] = df["ID"]
  </code></pre>
  
  <p>then get the </p>
  
  <pre><code>[value for key, value in programs.items() if 'ball' in key()]
  </code></pre>
  
  <p>but in this method i need to loop through dictionary and become slow</p>
  
  <p>if there is a method that i can apply faster without these processes, 
  i would prefer doing so.
  If anyone knows about this, 
  would appreciate a lot if you kindly let me know:)
  Thanks!</p>