标题已经说了。在已接受的答案中StackOverflow 34884536它说
You can find a longer discussion of the nature of the problem here, but the main take-away is that we're now moving to a "copy-on-write" behavior in which any time you slice, you get a new copy, and you never have to think about views.
...
Best guess is the fix will be in within a year -- in the mean time, I'm afraid some .copy() may be necessary, sorry!
(answered 2016/01/20)
df.loc[] 现在返回“副本”吗?或者为了安全起见,我仍然需要使用 .copy() 吗?
最佳答案
它返回一个副本。您可以通过制作副本、通过 .loc 将索引分配给另一个变量、更改变量并注意原始帧没有更改来测试这一点。
稍微相关,但更多信息请参见:http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
关于python - Pandas DataFrame df.loc 是 View 还是新的 DataFrame 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45703302/