title: Python Pandas - increment matching rows by 1
body: <p>I have the following code where a dataframe d has two columns with col1 of strings values and col2 with int values. </p>
  
  <p>I want to find all the rows matching to a pattern (using contains) and then increase the col2 values by 1 for the corresponding row. In the last line of my code where I am trying to increment by one I am getting following error:</p>
  
  <blockquote>
    <p>SettingWithCopyWarning:  A value is trying to be set on a copy of a
    slice from a DataFrame. Try using .loc[row_indexer,col_indexer] =
    value instead See the caveats in the documentation:
    <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy" rel="nofollow noreferrer">http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy</a>
    self[name] = value</p>
  </blockquote>
  
  <pre><code>import pandas as pd
  
  d = {'col1': ['abc', 'ave','abd', 'ave','abe', 'ave'], 'col2': [0,1,0,1,0,1]}
  
  df = pd.DataFrame(data=d)
  
  #print(df[df.col1.str.contains("ab")])
  
  df[df.col1.str.contains("ab")].col2 +=1
  </code></pre>
  
  <p>How can I increment the value using vector operation. I am trying to avoid for loop.</p>