Encode character string in the Series/Index using indicated encoding. Equivalent to :meth:`str.encode`. Parameters ---------- encoding : str Specifies the encoding to be used. errors : str, optional Specifies the error handli
(self, encoding, errors: str = "strict")
| 2435 | |
| 2436 | @forbid_nonstring_types(["bytes"]) |
| 2437 | def encode(self, encoding, errors: str = "strict"): |
| 2438 | """ |
| 2439 | Encode character string in the Series/Index using indicated encoding. |
| 2440 | |
| 2441 | Equivalent to :meth:`str.encode`. |
| 2442 | |
| 2443 | Parameters |
| 2444 | ---------- |
| 2445 | encoding : str |
| 2446 | Specifies the encoding to be used. |
| 2447 | errors : str, optional |
| 2448 | Specifies the error handling scheme. |
| 2449 | Possible values are those supported by :meth:`str.encode`. |
| 2450 | |
| 2451 | Returns |
| 2452 | ------- |
| 2453 | Series/Index of objects |
| 2454 | A Series or Index with strings encoded into bytes. |
| 2455 | |
| 2456 | See Also |
| 2457 | -------- |
| 2458 | Series.str.decode : Decodes bytes into strings in a Series/Index. |
| 2459 | |
| 2460 | Examples |
| 2461 | -------- |
| 2462 | >>> ser = pd.Series(["cow", "123", "()"]) |
| 2463 | >>> ser.str.encode(encoding="ascii") |
| 2464 | 0 b'cow' |
| 2465 | 1 b'123' |
| 2466 | 2 b'()' |
| 2467 | dtype: object |
| 2468 | """ |
| 2469 | result = self._data.array._str_encode(encoding, errors) |
| 2470 | return self._wrap_result(result, returns_string=False) |
| 2471 | |
| 2472 | @forbid_nonstring_types(["bytes"]) |
| 2473 | def strip(self, to_strip=None): |