-
Hi, So say I have the following rows
I'd like to calculate the mean and stdev of all rows AND columns where So I can group and aggregate like the following: ..but I really want to do so that it calculates the stdev between Is this possible? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I'm pretty confident there's a way but struggling -- you probably need to create a new column with an array of all the values and do some stuff. will drop this here for now: [ins] In [1]: import ibis
[ins] In [2]: import ibis.selectors as s
[ins] In [3]: ibis.options.interactive = True
...: ibis.options.repr.interactive.max_rows = 10
...: ibis.options.repr.interactive.max_columns = None
[ins] In [4]: data = {"row_type": ["type1", "type2", "type1"], "quantity_1": [10, 20, 30], "quantity_2": [11, 21, 31], "quantity_3": [12, 22, 32]}
[ins] In [5]: t = ibis.memtable(data)
[ins] In [6]: t.group_by("row_type").agg(s.across(s.contains("quantity"), ibis._.std()))
Out[6]:
┏━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ row_type ┃ quantity_1 ┃ quantity_2 ┃ quantity_3 ┃
┡━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ string │ float64 │ float64 │ float64 │
├──────────┼────────────┼────────────┼────────────┤
│ type1 │ 14.142136 │ 14.142136 │ 14.142136 │
│ type2 │ NULL │ NULL │ NULL │
└──────────┴────────────┴────────────┴────────────┘ someone more experienced can probably chime in at some point (though much of the team is at PyCon this week) with a solution |
Beta Was this translation helpful? Give feedback.
-
You can do this with
|
Beta Was this translation helpful? Give feedback.
You can do this with
group_by
, but you need to pivot the data into a longer form first: