split string with numpy python

Solutions on MaxInterview for split string with numpy python by the best coders in the world

showing results for - "split string with numpy python"
Kaelyn
12 Jan 2021
1# Split string inside numpay array  
2import numpy as np
3
4# In this case I want to remove everything before " – "
5# to stay only with --> "I have a friendly staff", "Friendly staff advice for..."
6
7array = ['Linda Rodway – I have a friendly staff', 
8 'Kevin Ransom – Friendly staff advice for...']
9
10# Create numpy array
11a = np.array(array)
12# Now you can split using .split method and loop through all inside a
13b = np.array([x.split(' – ')[1] for x in a])
14
15# in this case if you remove [1] you will see the following result:
16# 'Linda Rodway', 'I have a friendly staff', and you use [1] to show only
17# the second one 'I have a friendly staff'
18