NumPy char | rstrip method
np.char.rstrip(~) method takes as input an array of strings, and removes specified characters on the right side of each string.
Note that the original array is left intact, and a brand new copy of the array is returned.
The input array of strings.
The characters located on the right side of string that you want removed. Note that if
chars="ab", for instance, the characters that will be removed will be the combinations of the parameter value, that is,
A new Numpy array with the specified characters residing at the right of the input strings removed.
Removing right whitespaces
np.char.rstrip(["Hello ", "World "])array(['Hello', 'World'], dtype='<U8')
Removing right custom characters
np.char.rstrip(["zba", "zab"], "ab")array(['z', 'z'], dtype='<U3')
Notice how both
"ab" were removed - it's the combinations of the specified characters that are removed.