Pandas replacing values on specific columns
<p>I am aware of these two similar questions:</p>

<p><a href="https://stackoverflow.com/questions/27117773/pandas-replace-values">Pandas replace values</a></p>

<p><a href="https://stackoverflow.com/questions/23307301/pandas-replacing-column-values-in-dataframe">Pandas: Replacing column values in dataframe</a></p>

<p>I used a different approach for substituting values from which I think it should be the cleanest one. But it does not work. I know how to work around it, but I would like to understand why it does not work:</p>

<pre><code>In [108]: df=pd.DataFrame([[1, 2, 8],[3, 4, 8], [5, 1, 8]], columns=['A', 'B', 'C']) 

In [109]: df
Out[109]: 
   A  B  C
0  1  2  8
1  3  4  8
2  5  1  8

In [110]: df.loc[:, ['A', 'B']].replace([1, 3, 2], [3, 6, 7], inplace=True)

In [111]: df
Out[111]: 
   A  B  C
0  1  2  8
1  3  4  8
2  5  1  8

In [112]: df.loc[:, 'A'].replace([1, 3, 2], [3, 6, 7], inplace=True)

In [113]: df
Out[113]: 
   A  B  C
0  3  2  8
1  6  4  8
2  5  1  8
</code></pre>

<p>If I slice only one column <code>In [112]</code> it works different to slicing several columns <code>In [110]</code>. As I understand the <code>.loc</code> method it returns a view and not a copy. In my logic this means that making an inplace change on the slice should change the whole DataFrame. This is what happens at line <code>In [110]</code>.</p>