1

For example

import pandas as pd
d1 = pd.Series(['a b', 'c d'])
t1 = d1.str.split()
a1 = t1.values

where a1 would be

array([list(['a', 'b']), list(['c', 'd'])], dtype=object)

how to transform it to

array([['a', 'b'],
       ['c', 'd']], dtype='<U1')

1 Answer 1

1

Use np.stack on t1:

In [186]: np.stack(t1)
Out[186]:
array([['a', 'b'],
       ['c', 'd']], dtype='<U1')

Or np.array on t1.tolist

In [187]: np.array(t1.tolist())
Out[187]:
array([['a', 'b'],
       ['c', 'd']], dtype='<U1')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.