Skip to content

dynamic underscore selector #6921

Answered by gforsyth
ozgurkalan asked this question in Q&A
Aug 23, 2023 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

Hey @ozgurkalan -- there are a few ways you can do this:

  1. Make use of getattr for grabbing the column name associated with your variable:
[ins] In [23]: var
Out[23]: 'bill_length_mm'

[ins] In [24]: penguins.aggregate(getattr(_, var).sum(), by="year")
Out[24]: 
┏━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃ yearSum(bill_length_mm) ┃
┡━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ int64float64             │
├───────┼─────────────────────┤
│  20074767.7 │
│  20084963.7 │
│  20095289.9 │
└───────┴─────────────────────┘
  1. Use a selector
[ins] In [25]: import ibis.selectors as s

[ins] In [26]: var
Out[26]: 'bill_length_mm'

[ins] In [27]: penguins.aggregate(s.across(

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@ozgurkalan
Comment options

@jcrist
Comment options

@ozgurkalan
Comment options

Answer selected by ozgurkalan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants