Skip to content

Rename count column without extra select statement #8216

Closed Answered by lostmygithubaccount
saschahofmann asked this question in Q&A
Discussion options

You must be logged in to vote

hi @saschahofmann, if you want to explicitly name your aggregations you can do something like this:

[ins] In [1]: import ibis

[ins] In [2]: ibis.options.interactive = True

[ins] In [3]: t = ibis.examples.penguins.fetch()

[nav] In [4]: expr = t.group_by(t.species).agg(CountPenguins=ibis._.count())

[ins] In [5]: expr
Out[5]:
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ speciesCountPenguins ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ stringint64         │
├───────────┼───────────────┤
│ Adelie152 │
│ Chinstrap68 │
│ Gentoo124 │
└───────────┴───────────────┘

[ins] In [6]: ibis.to_sql(expr)
Out[6]:
SELECT
  t0.species,
  COUNT(*) AS "CountPenguins"
FROM main

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@saschahofmann
Comment options

Answer selected by gforsyth
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants