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:
pyarrow.Table
a: string
----
a: [["one_frobenius","two_frobenius","three_frobenius"]]
You can use pyarrow.compute.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"]]
You might convert to the pandas Dataframe, modify the strings, and convert back. For example,
>>> import pyarrow as pa
>>> t = pa.table({'a': ['one', 'two', 'three']})
>>> df = t.to_pandas()
>>> df
a
0 one
1 two
2 three
>>> df['a'] = df['a'] + '_frobenius'
>>> df
a
0 one_frobenius
1 two_frobenius
2 three_frobenius
>>> new_table = t.set_column(0, 'a', pa.array(df['a']))
>>> new_table
pyarrow.Table
a: string
----
a: [["one_frobenius","two_frobenius","three_frobenius"]]