python - Pandas DataFrame df.loc 是 View 还是新的 DataFrame 对象?

标签 python pandas dataframe

标题已经说了。在已接受的答案中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/

相关文章:

python - Tensorflow:Word2vec CBOW 模型

python - Python非正式入门斐波那契数列 "b (None,)"的结果

python - Pandas Dataframe : df. 应用忽略错误行

python pandas 将数据框更改为旋转列

Python 任务 : Searching for a value in a column and get the value of a different column

python - 如何删除列表中列表中的第一个元素?

python - "The location of Firebird Client Library could not be determined."

基于第二列的 Pandas DataFrame 过滤

python - 如何将虚拟列连接到主表?

python - 使用从 Postgres 中提取的数据框在 Python 中创建计算列(使用 If 语句)