'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 1:[1]
np.char module has a bunch of functions that apply string methods to a U dtype array. It's not faster than doing the equivalent list comprehension, but may be more convenient.
In [19]: arr = np.array(['USD/EUR', 'nan'])
In [20]: arr
Out[20]: array(['USD/EUR', 'nan'], dtype='<U7')
In [21]: np.char.split(arr, '/')
Out[21]: array([list(['USD', 'EUR']), list(['nan'])], dtype=object)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | hpaulj |
