Python | Панды Series.str.decode ()
Series.str can be used to access the values of the series as strings and apply several methods to it. Pandas Series.str.decode() function is used to decode character string in the Series/Index using indicated encoding. This function is equivalent to str.decode() in python2 and bytes.decode() in python3.
Syntax: Series.str.decode(encoding, errors=’strict’)
Parameter :
encoding : str
errors : str, optionalReturns : decoded Series/Index of objects
Example #1: Use Series.str.decode() function to decode the character strings in the underlying data of the given series object. Use ‘UTF-8’ encoding method.
Выход :

Now we will use Series.str.decode() function to decode the character strings in the underlying data of the given series object.
# use "UTF-8" encodingresult = sr.str.decode(encoding = "UTF-8") # print the resultprint(result) |
Выход :

As we can see in the output, the Series.str.decode() function has successfully decodes the strings in the underlying data of the given series object.
Example #2 : Use Series.str.decode() function to decode the character strings in the underlying data of the given series object. Use ‘ASCII’ encoding method.
# importing pandas as pdimport pandas as pd # Creating the Seriessr = pd.Series([b"Mike-", b"Alessa-", b"Nick-", b"Kim-", b"Britney-"]) # Creating the indexidx = ["Name 1", "Name 2", "Name 3", "Name 4", "Name 5"] # set the indexsr.index = idx # Print the seriesprint(sr) |
Выход :

Now we will use Series.str.decode() function to decode the character strings in the underlying data of the given series object.
# use "ASCII" encodingresult = sr.str.decode(encoding = "ASCII") # print the resultprint(result) |
Выход :

As we can see in the output, the Series.str.decode() function has successfully decodes the strings in the underlying data of the given series object.
Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.
Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.