Python | Панды Series.from_array ()
Серия Pandas - это одномерный массив ndarray с метками осей. Этикетки не обязательно должны быть уникальными, но должны быть хешируемого типа. Объект поддерживает индексирование как на основе целых чисел, так и на основе меток и предоставляет множество методов для выполнения операций, связанных с индексом.
Pandas Series.from_array() function construct a Series object from an array. We can also set the name and index of the series at the time of creation.
Syntax: Series.from_array(arr, index=None, name=None, dtype=None, copy=False, fastpath=False)
Parameter :
arr : array to be used for construction of series
index : set the index of the series
name : Set the name of the seriesReturns : series
Example #1: Use Series.from_array() function to construct a series object from an array.
# importing pandas as pdimport pandas as pd # Creating an arrayarray = ["New York", "Chicago", "Toronto", "Lisbon", "Rio"] # Create the Indexindex_ = ["City 1", "City 2", "City 3", "City 4", "City 5"] # Creating the seriessr = pd.Series.from_array(arr = array, index = index_) # Print the seriesprint(sr) |
Выход :

As we can see in the output, the Series.from_array() function has successfully constructed a series object from an array.
Example #2: Use Series.from_array() function to construct a series object from an array. Also set the name of the series
# importing pandas as pdimport pandas as pd # Creating an arrayarray = [11, 21, 8, 18, 65, 84, 32, 10, 5, 24, 32] # Create the Indexindex_ = pd.date_range("2010-10-09", periods = 11, freq ="M") # Creating the series# set the index# set the namesr = pd.Series.from_array(arr = array, index = index_, name = "My_series") # Print the seriesprint(sr) |
Выход :

As we can see in the output, the Series.from_array() function has successfully constructed a series object from an array. We have also set the name of the series.
Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.
Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.