Pandas Series: str.rstrip() function
Series-str.rstrip() function
The str.rstrip() function is used to remove leading and trailing characters.
Strip whitespaces (including newlines) or a set of specified characters from each string in the Series/Index from right side. Equivalent to str.rstrip()..
Syntax:
Series.str.rstrip(self, to_strip=None)
Parameters:
Name | Description | Type/Default Value | Required / Optional |
---|---|---|---|
to_strip | Specifying the set of characters to be removed. All combinations of this set of characters will be stripped. If None then whitespaces are removed. | str or None, default None | Required |
Returns: Series/Index of objects.
Example:
Python-Pandas Code:
import numpy as np
import pandas as pd
s = pd.Series(['1. Dog. ', '2. Bat!\n', '3. Fox?\t', np.nan])
s
Output:
0 1. Dog. 1 2. Bat!\n 2 3. Fox?\t 3 NaN dtype: object
Python-Pandas Code:
import numpy as np
import pandas as pd
s = pd.Series(['1. Dog. ', '2. Bat!\n', '3. Fox?\t', np.nan])
s.str.rstrip('.!? \n\t')
Output:
0 1. Dog 1 2. Bat 2 3. Fox 3 NaN dtype: object
Previous: Series-str.rpartition() function
Next: Series-str.slice() function
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://w3resource.com/pandas/series/series-str-rstrip.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics