title: Pandas DataFrame: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame
body: <p>I know there are tons of posts about this warning, but I couldn't find a solution to my situation. Here's my code:</p>
  
  <pre><code>df.loc[:, 'my_col'] = df.loc[:, 'my_col'].astype(int)
  #df.loc[:, 'my_col'] = df.loc[:, 'my_col'].astype(int).copy()
  #df.loc[:, 'my_col'] = df['my_col'].astype(int)
  </code></pre>
  
  <p>It produces the warning:</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</p>
  </blockquote>
  
  <p>Even though I changed the code as suggested, I still get this warning? All I need to do is to convert the data type of one column. </p>
  
  <p>**Remark: ** Originally the column is of type float having one decimal (example: 4711.0). Therefore I change it to integer (4711) and then to string ('4711') - just to remove the decimal.</p>
  
  <p>Appreciate your help!</p>
  
  <p><strong>Update:</strong> The warning was a side effect on a filtering of the original data that was done just before. I was missing the DataFrame.copy(). Using the copy instead, solved the problem!</p>
  
  <pre><code>df = df[df['my_col'].notnull()].copy()
  df.loc[:, 'my_col'] = df['my_col'].astype(int).astype(str)
  #df['my_col'] = df['my_col'].astype(int).astype(str) # works too!
  </code></pre>