捷徑

torcharrow.DataFrame.where

DataFrame.where(*conditions)

類似於 SQL 的 where(不是 Pandas 的 where)

篩選 DataFrame,僅包含滿足給定條件集的列。 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

文件

存取 PyTorch 的完整開發者文件

查看文件

教學課程

取得適用於初學者和進階開發者的深入教學課程

查看教學課程

資源

尋找開發資源並獲得問題解答

查看資源