Pandas Series str | lstrip method
Start your free 7-days trial now!
Pandas Series str.lstrip(~) method removes the combination of the specified characters that appear from the left of each string in the Series.
Note that a new Series is returned, and the original is kept intact.
Parameters
1. to_strip | str or None | optional
The combination of the characters of to_strip that appears at the front of each string will be removed. For instance, if to_strip="ab", then abA and baA will both become A.
By default, leading whitespaces (including newlines and tabs) will be removed.
Return Value
A new Series or Index.
Examples
Basic usage
By default, lstrip(~) removes leading whitespaces (including newlines and tabs):
0 1 a a2 a3 adtype: object
To confirm that the whitespaces have indeed been stripped, we print the length of each string:
0 01 32 13 1dtype: int64
Specifying to_strip
To remove a combination of the characters "ab" at the front:
s.str.lstrip("ab")
0 A1 Adtype: object
Here, notice how "baA" got stripped down to "A" - this is because a combination of the specified characters is stripped ("ab" and "ba" in this case).