Shortcuts

torcharrow.DataFrame.where

DataFrame.where(*conditions)

类似于SQL的where(不是Pandas的where)

过滤数据框,仅包含满足给定条件的行。df.where(p) 等同于写 df[p]。

示例

>>> from torcharrow import ta
>>> xf = ta.dataframe({
>>>    'A':['a', 'b', 'a', 'b'],
>>>    'B': [1, 2, 3, 4],
>>>    'C': [10,11,12,13]})
>>> xf.where(xf['B']>2)
  index  A      B    C
-------  ---  ---  ---
      0  a      3   12
      1  b      4   13
dtype: Struct([Field('A', string), Field('B', int64), Field('C', int64)]), count: 2, null_count: 0

在表达式中引用自身时,可以使用特殊值 me

>>> from torcharrow import me
>>> xf.where(me['B']>2)
  index  A      B    C
-------  ---  ---  ---
      0  a      3   12
      1  b      4   13
dtype: Struct([Field('A', string), Field('B', int64), Field('C', int64)]), count: 2, null_count: 0