NumPy: numpy.char.lstrip() function
numpy.char.lstrip() function
The numpy.char.lstrip() function is used to remove leading characters (typically whitespace) from the elements of a string array or a single string.
This function is useful in 'Data cleaning', 'Text processing', 'Data preprocessing' etc.
Syntax:
numpy.char.lstrip(a, chars=None)
Parameters:
Name | Description | Required / Optional |
---|---|---|
a | Input array. | Required |
chars | Separator to split each string element in a. | Optional |
Return value:
Output array of str or unicode, depending on input type.
Example: Removing leading whitespaces from a string using NumPy
import numpy as np
str1 = ' Python NumPy'
print("Original string: ",str1)
print("After leading whitepsace are removed:")
print(np.char.lstrip(str1))
Output:
Original string: Python NumPy After leading whitepsace are removed: Python NumPy
In the above example, the numpy.char.lstrip() function is used to demonstrate how to remove leading whitespace characters from a string using NumPy. The 'numpy.char.lstrip()' function is called with the input string str1. This function removes all leading whitespace characters from the input string and returns the modified string.
Pictorial Presentation:
Python - NumPy Code Editor:
Previous:
lower()
Next:
partition()
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/numpy/string-operations/lstrip.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics