python - 为什么我在熊猫重新分配中得到弱引用?
问题描述
我想摆脱索引isin
列表的行["A", "C"]
。
例子:
import pandas as pd
df_test = pd.DataFrame({"Col": [1,2,3,4]}, index=["A", "B", "C", "D"])
Col A 1 B 2 C 3 D 4
现在我重新分配:
df_test = df_test[~df_test.index.isin(["A", "C"])]
我试图理解以下结果。
df_test._is_copy
(* <weakref at 0x11d14a4a8; to 'DataFrame' at 0x11d0dbac8> *)
为什么我
weakref
在这里得到副本?消除索引在给定列表中的行是否正确?我应该用
.loc[:,:]
左边还是.copy()
右边?
解决方案
推荐阅读
- bash - 运行“open -a Terminal.app MyScript”,打开新的终端窗口,但不在其中运行 MyScript
- excel - VBA:在选定的 Excel 选项卡上运行代码并在右侧的所有选项卡上连续运行代码
- java - 使用 Java 8 功能在列表中搜索非空列表
- flask - 将可选的 JSON Post 参数传递给 Flask-RestFul?
- angular - 如何检测Angular中的属性更改
- excel - 使用 Excel 宏 Vba 将文件上传到网页(IE11)
- python - 使用 paramiko 在 ssh 上运行 python 脚本未按预期工作
- awk - 匹配字符串,但只输出它下面的行+不是匹配的字符串本身
- r - R:热图(数据)错误:“x”必须是数字矩阵。它指的是哪个“x”?
- java - Springboot - 带有注入的@Autowired null