-
I have constructed an Ibis dataframe that includes a column named account_id. I would like to hash and modulo this column and assign the result to a new column. I am using ClickHouse as the backend, which has the halfMD5 function. |
Beta Was this translation helpful? Give feedback.
Answered by
gforsyth
May 8, 2024
Replies: 1 comment
-
Hey @stereoF -- you can use a [ins] In [1]: import ibis
[ins] In [2]: con = ibis.clickhouse.connect()
[ins] In [3]: ibis.options.interactive = True
[ins] In [4]: ibis.set_backend(con)
[ins] In [5]: t = ibis.memtable({"b": ["hey", "yo"]})
[ins] In [6]: t
Out[6]:
┏━━━━━━━━┓
┃ b ┃
┡━━━━━━━━┩
│ string │
├────────┤
│ hey │
│ yo │
└────────┘
[ins] In [7]: @ibis.udf.scalar.builtin
...: def halfMD5(val) -> int: ...
[ins] In [8]: t.mutate(c=halfMD5(t.b))
Out[8]:
┏━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃ b ┃ c ┃
┡━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ string │ int64 │
├────────┼─────────────────────┤
│ hey │ 6942282591847239551 │
│ yo │ 7854286431059639165 │
└────────┴─────────────────────┘ |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
cpcloud
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @stereoF -- you can use a
builtin
UDF for this: