Python | Панды Series.to_string ()
Серия Pandas - это одномерный массив ndarray с метками осей. Этикетки не обязательно должны быть уникальными, но должны быть хешируемого типа. Объект поддерживает индексирование как на основе целых чисел, так и на основе меток и предоставляет множество методов для выполнения операций, связанных с индексом.
Pandas Series.to_string() function render a string representation of the Series.
Syntax: Series.to_string(buf=None, na_rep=’NaN’, float_format=None, header=True, index=True, length=False, dtype=False, name=False, max_rows=None)
Parameter :
buf : buffer to write to
na_rep : string representation of NAN to use, default ‘NaN’
float_format : formatter function to apply to columns’ elements if they are floats default None
header : Add the Series header (index name)
index : Add index (row) labels, default True
length : Add the Series length
dtype : Add the Series dtype
name : Add the Series name if not None
max_rows : Maximum number of rows to show before truncating.Returns : Formatted string.
Example #1: Use Series.to_string() function to render a string representation of the given series object.
# importing pandas as pdimport pandas as pd # Creating the Seriessr = pd.Series(["New York", "Chicago", "Toronto", "Lisbon", "Rio", "Moscow"]) # Create the Datetime Indexdidx = pd.DatetimeIndex(start ="2014-08-01 10:00", freq ="W", periods = 6, tz = "Europe/Berlin") # set the indexsr.index = didx # Print the seriesprint(sr) |
Выход :

Now we will use Series.to_string() function to render string representation to this series object.
# render to string formsr.to_string() |
Выход :

As we can see in the output, the Series.to_string() function has successfully rendered a string representation to the given object.
Example #2: Use Series.to_string() function to render a string representation of the given series object.
# importing pandas as pdimport pandas as pd # Creating the Seriessr = pd.Series([19.5, 16.8, 22.78, 20.124, 18.1002]) # Print the seriesprint(sr) |
Выход :

Now we will use Series.to_string() function to render string representation to this series object.
# render to string formsr.to_string() |
Выход :

As we can see in the output, the Series.to_string() function has successfully rendered a string representation to the given object.
Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.
Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.