Pandas Series str | lstrip method
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.
The combination of the characters of
to_strip that appears at the front of each string will be removed. For instance, if
baA will both become
By default, leading whitespaces (including newlines and tabs) will be removed.
lstrip(~) removes leading whitespaces (including newlines and tabs):
s = pd.Series([" ","a a","\na","\ta"])s_stripped = s.str.lstrip()s_stripped01 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
To remove a combination of the characters
"ab" at the front:
s = pd.Series(["abA","baA"])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 (
"ba" in this case).