QST: Wish to know how to properly avoid SettingwithCopyWarning without changing dtype
- [X] I have searched the [[pandas] tag](https://stackoverflow.com/questions/tagged/pandas) on StackOverflow for similar questions.

- [ ] I have asked my usage related question on [StackOverflow](https://stackoverflow.com).
---

#### Question about pandas

The data dataframe's label column is dtype: float64, and consists of four numbers, `[ 0.,  2.,  1.,  3., nan]`.
```python
data[label_column][data[label_column] != 2] = 0
```
produces a SettingWithCopyWarning as it should. However,

```python
data.loc[data[label_column] != 2, label_column] = 0
```
does not produce a SettingWithCopyWarning, but changes the column to dtype: object.

I recognize `.loc` tries to cast back to the original dtype on assignment and `[]` does not based on [the getting started docs](http://pandas-docs.github.io/pandas-docs-travis/getting_started/basics.html), but I would like to know if the expected behaviour in this situation is expected and what the proper syntax I should use to avoid the warning but preserve the dtype. 