【发布时间】:2017-05-19 22:11:45
【问题描述】:
我有一个示例 pandas 数据框 df:
col1 col2 col3 col4
0 a 1.0 2.0 3
1 b NaN NaN 6
2 c NaN 8.0 9
3 d NaN 11.0 12
4 e 13.0 14.0 15
5 f 17.0 18.0 19
6 g 21.0 22.0 23
还有第二个df1:
col1 col2 col3 col4
0 a 1.0 2.0 3
4 e 13.0 14.0 15
5 f 17.0 18.0 19
6 g 21.0 22.0 23
我想得到不与 df1 重叠的 df 子集。实际上,我正在寻找 SQL 中 EXCEPT 操作数的等价物。
我使用了减法() 函数——但这显然是错误的,因为减法执行的是元素数值减法。所以我收到一条错误消息:
TypeError: unsupported operand type(s) for -: 'str' and 'str'
所以问题是:对于 Pandas,SQL 中 EXCEPT 的等价物是什么?
【问题讨论】:
-
那么错误很明显,你不能减去字符串,除了你没有发布所需的输出应该是什么。