Split the string at the last occurrence of `sep`. This method splits the string at the last occurrence of `sep`, and returns 3 elements containing the part before the separator, the separator itself, and the part after the separator. If the separator is not
(self, sep: str = " ", expand: bool = True)
| 1121 | |
| 1122 | @forbid_nonstring_types(["bytes"]) |
| 1123 | def rpartition(self, sep: str = " ", expand: bool = True): |
| 1124 | """ |
| 1125 | Split the string at the last occurrence of `sep`. |
| 1126 | |
| 1127 | This method splits the string at the last occurrence of `sep`, |
| 1128 | and returns 3 elements containing the part before the separator, |
| 1129 | the separator itself, and the part after the separator. |
| 1130 | If the separator is not found, return 3 elements containing two empty strings, |
| 1131 | followed by the string itself. |
| 1132 | |
| 1133 | Parameters |
| 1134 | ---------- |
| 1135 | sep : str, default " " |
| 1136 | String to split on. |
| 1137 | expand : bool, default True |
| 1138 | If True, return DataFrame/MultiIndex expanding dimensionality. |
| 1139 | If False, return Series/Index. |
| 1140 | |
| 1141 | Returns |
| 1142 | ------- |
| 1143 | DataFrame/MultiIndex or Series/Index of objects |
| 1144 | Returns appropriate type based on `expand` parameter with strings |
| 1145 | split based on the `sep` parameter. |
| 1146 | |
| 1147 | See Also |
| 1148 | -------- |
| 1149 | partition : Split the string at the first occurrence of `sep`. |
| 1150 | Series.str.split : Split strings around given separators. |
| 1151 | str.partition : Standard library version. |
| 1152 | |
| 1153 | Examples |
| 1154 | -------- |
| 1155 | >>> s = pd.Series(["Linda van der Berg", "George Pitt-Rivers"]) |
| 1156 | >>> s |
| 1157 | 0 Linda van der Berg |
| 1158 | 1 George Pitt-Rivers |
| 1159 | dtype: str |
| 1160 | |
| 1161 | >>> s.str.partition() |
| 1162 | 0 1 2 |
| 1163 | 0 Linda van der Berg |
| 1164 | 1 George Pitt-Rivers |
| 1165 | |
| 1166 | To partition by the last space instead of the first one: |
| 1167 | |
| 1168 | >>> s.str.rpartition() |
| 1169 | 0 1 2 |
| 1170 | 0 Linda van der Berg |
| 1171 | 1 George Pitt-Rivers |
| 1172 | |
| 1173 | To partition by something different than a space: |
| 1174 | |
| 1175 | >>> s.str.partition("-") |
| 1176 | 0 1 2 |
| 1177 | 0 Linda van der Berg |
| 1178 | 1 George Pitt - Rivers |
| 1179 | |
| 1180 | To return a Series containing tuples instead of a DataFrame: |