Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Why is it that setting a value on a dataframe that is (I think) a copy changing the original dataframe?

$
0
0

I create a dataframe and (I think) I create a copy out of it. I think I create a copy out of it since ._is_view property is False

import pandas as pddf = pd.DataFrame({'a':[1,2,3],'b':['x','y','z']})df.loc[[True, True, False],'a']._is_viewoutput: False

So setting this copy equal to some value should not change the original dataframe, right?

However, the following changes the original dataframe

df.loc[[True, True, False],'a'] = 'abcd'print(df)output:      a  b0  abcd  x1  abcd  y2     3  z

Can you please help me understand this behavior by pandas?


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>