MCPcopy
hub / github.com/pandas-dev/pandas / encode

Method encode

pandas/core/strings/accessor.py:2437–2470  ·  view source on GitHub ↗

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")

Source from the content-addressed store, hash-verified

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):

Callers 15

time_encode_decodeMethod · 0.80
setupMethod · 0.80
setupMethod · 0.80
_str_encodeMethod · 0.80
_str_encodeMethod · 0.80
_get_data_bufferMethod · 0.80
_get_offsets_bufferMethod · 0.80
_convert_string_arrayFunction · 0.80
_parse_docMethod · 0.80

Calls 2

_wrap_resultMethod · 0.95
_str_encodeMethod · 0.45

Tested by 15

test_empty_str_methodsFunction · 0.64
test_encode_decodeFunction · 0.64
test_encode_errors_kwargFunction · 0.64
test_astype_unicodeMethod · 0.64
test_strl_latin1Method · 0.64
csv_responderFunction · 0.64
json_responderFunction · 0.64
html_responderFunction · 0.64
test_read_csvFunction · 0.64