Python | Панды Series.quantile ()

Опубликовано: 27 Марта, 2022

Серия Pandas - это одномерный массив ndarray с метками осей. Этикетки не обязательно должны быть уникальными, но должны быть хешируемого типа. Объект поддерживает индексирование как на основе целых чисел, так и на основе меток и предоставляет множество методов для выполнения операций, связанных с индексом.

Pandas Series.quantile() function return value at the given quantile for the underlying data in the given Series object.

Syntax: Series.quantile(q=0.5, interpolation=’linear’)

Parameter :
q : float or array-like, default 0.5 (50% quantile)
interpolation : {‘linear’, ‘lower’, ‘higher’, ‘midpoint’, ‘nearest’}

Returns : quantile : float or Series

Example #1: Use Series.quantile() function to return the desired quantile of the underlying data in the given Series object.

# importing pandas as pd
import pandas as pd
  
# Creating the Series
sr = pd.Series([10, 25, 3, 11, 24, 6])
  
# Create the Index
index_ = ["Coca Cola", "Sprite", "Coke", "Fanta", "Dew", "ThumbsUp"]
  
# set the index
sr.index = index_
  
# Print the series
print(sr)

Выход :

Now we will use Series.quantile() function to find the 40% quantile of the underlying data in the given series object.

# return the value of 40 % quantile
result = sr.quantile(q = 0.4)
  
# Print the result
print(result)

Выход :

As we can see in the output, the Series.quantile() function has successfully returned the desired qunatile value of the underlying data of the given Series object.

Example #2: Use Series.quantile() function to return the desired quantile of the underlying data in the given Series object.

Выход :

Now we will use Series.quantile() function to find the 90% quantile of the underlying data in the given series object.

# return the value of 90 % quantile
result = sr.quantile(q = 0.9)
  
# Print the result
print(result)

Выход :

As we can see in the output, the Series.quantile() function has successfully returned the desired qunatile value of the underlying data of the given Series object.

Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.

Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.