-
When using filter, for a specific column, I want to check if the current value is not just one specific value, but whether it's present in a list of strings for example. I get deferred errors because the truth value hasn't been instantiated yet, unlike if I compare to a constant. I've tried find_in_set as well, but I get a SignatureValidationError? What is the best approach here? I want to mirror what KQL is doing with this. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @oystesla ! You're looking for the [ins] In [8]: t
Out[8]:
┏━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━┓
┃ species ┃ island ┃ bill_length_mm ┃ bill_depth_mm ┃ flipper_length_mm ┃ … ┃
┡━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━┩
│ string │ string │ float64 │ float64 │ int64 │ … │
├─────────┼───────────┼────────────────┼───────────────┼───────────────────┼───┤
│ Adelie │ Torgersen │ 39.1 │ 18.7 │ 181 │ … │
│ Adelie │ Torgersen │ 39.5 │ 17.4 │ 186 │ … │
│ Adelie │ Torgersen │ 40.3 │ 18.0 │ 195 │ … │
│ Adelie │ Torgersen │ NULL │ NULL │ NULL │ … │
│ Adelie │ Torgersen │ 36.7 │ 19.3 │ 193 │ … │
│ Adelie │ Torgersen │ 39.3 │ 20.6 │ 190 │ … │
│ Adelie │ Torgersen │ 38.9 │ 17.8 │ 181 │ … │
│ Adelie │ Torgersen │ 39.2 │ 19.6 │ 195 │ … │
│ Adelie │ Torgersen │ 34.1 │ 18.1 │ 193 │ … │
│ Adelie │ Torgersen │ 42.0 │ 20.2 │ 190 │ … │
│ … │ … │ … │ … │ … │ … │
└─────────┴───────────┴────────────────┴───────────────┴───────────────────┴───┘
[ins] In [9]: t.bill_length_mm.mean()
Out[9]:
┌──────────┐
│ 43.92193 │
└──────────┘
[ins] In [10]: t.filter(t.species.isin(["Dream", "Adelie"])).bill_length_mm.mean()
Out[10]:
┌───────────┐
│ 38.791391 │
└───────────┘ |
Beta Was this translation helpful? Give feedback.
Hey @oystesla !
You're looking for the
isin
method on the column in question -- you can pass that a list of options and if the column value matches any of them, then it will returnTrue