【问题标题】:Curious about the function of ~in the following code [duplicate]好奇以下代码中~的功能[重复]
【发布时间】:2021-06-16 12:01:03
【问题描述】:
pd_selftest = pd_selftest[pd_selftest['SICCD'] != 0]

pd_selftest = pd_selftest[~pd_selftest['SICCD'].isnull()]

我想知道上面代码中~的作用是什么。

【问题讨论】:

  • ~[True,False,True] == [False,True,False]

标签: python


【解决方案1】:

这是按位的invertnot 运算符。因此,它只返回SICCID 列不为空的那些行。在这种情况下,我可能会使用 not 这个词。

【讨论】:

  • not 不适用于结果向量,而 ~ 则适用; not 在 OP 的情况下可能不起作用。
猜你喜欢
  • 1970-01-01
  • 2021-07-01
  • 2022-01-19
  • 1970-01-01
  • 1970-01-01
  • 2022-07-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多