How to create a json column, based on other columns? #11051
Answered
by
gforsyth
felipeangelimvieira
asked this question in
Q&A
-
Hello, Thank you for this amazing lib. tbl = tbl.mutate(
json_column=ibis.json({"column_b": _.ColumnB})
) Is there a way to achieve this? |
Beta Was this translation helpful? Give feedback.
Answered by
gforsyth
Mar 28, 2025
Replies: 1 comment 3 replies
-
Hwy @felipeangelimvieira -- if the backend supports JSON and the column you want to convert can be coerced into JSON, then you can accomplish this with a [ins] In [18]: t
Out[18]:
┏━━━━━━━┳━━━━━━━━━━━━━━━━━━┓
┃ a ┃ b ┃
┡━━━━━━━╇━━━━━━━━━━━━━━━━━━┩
│ int64 │ string │
├───────┼──────────────────┤
│ 1 │ {"key": "value"} │
│ 2 │ {"key": "value"} │
│ 3 │ {"key": "value"} │
└───────┴──────────────────┘
[ins] In [19]: t.mutate(c=t.b.cast('json'))
Out[19]:
┏━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┓
┃ a ┃ b ┃ c ┃
┡━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━┩
│ int64 │ string │ json │
├───────┼──────────────────┼──────────────────────┤
│ 1 │ {"key": "value"} │ {'key': 'value'} │
│ 2 │ {"key": "value"} │ {'key': 'value'} │
│ 3 │ {"key": "value"} │ {'key': 'value'} │
└───────┴──────────────────┴──────────────────────┘ |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah, ok, so something like
?