Python: numpy.ndarray split

I have array(['USD/EUR', 'nan'], dtype='<U32') that I want to split so that I get [USD, EUR]. How can this be done?

The .split function is not working for me.

>Solution :

If you only care about the element 'USD/EUR', then just extract it, then use split(), specifying that the split should be on the '/' character:

import numpy as np

a = np.array(['USD/EUR', 'nan'], dtype='<U32')
b = a[0].split('/')
print(b)

Leave a Reply