Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to append string to each element of chunked array?

Say I have

In [22]: import pyarrow as pa

In [23]: t = pa.table({'a': ['one', 'two', 'three']})

and I’d like to append '_frobenius' to each element of 'a'

Expected output:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

pyarrow.Table
a: string
----
a: [["one_frobenius","two_frobenius","three_frobenius"]]

>Solution :

You can use pc.binary_join_element_wise to join a fixed string to each element:

import pyarrow as pa
import pyarrow.compute as pc

t = pa.table({"a": ["one", "two", "three"]})

t = t.set_column(0, "a", pc.binary_join_element_wise(t["a"], "_frobenius", ""))

print(t)

Output:

pyarrow.Table
a: string
----
a: [["one_frobenius","two_frobenius","three_frobenius"]]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading