Python | Панды dataframe.quantile ()
Python - отличный язык для анализа данных, в первую очередь из-за фантастической экосистемы пакетов Python, ориентированных на данные. Pandas - один из таких пакетов, который значительно упрощает импорт и анализ данных.
Pandas dataframe.quantile() function return values at the given quantile over requested axis, a numpy.percentile.
Примечание: в каждом из любого набора значений переменной, которые делят частотное распределение на равные группы, каждая из которых содержит одинаковую долю от общей совокупности.
Syntax: DataFrame.quantile(q=0.5, axis=0, numeric_only=True, interpolation=’linear’)
Parameters :
q : float or array-like, default 0.5 (50% quantile). 0 <= q <= 1, the quantile(s) to compute
axis : [{0, 1, ‘index’, ‘columns’} (default 0)] 0 or ‘index’ for row-wise, 1 or ‘columns’ for column-wise
numeric_only : If False, the quantile of datetime and timedelta data will be computed as well
interpolatoin : {‘linear’, ‘lower’, ‘higher’, ‘midpoint’, ‘nearest’}Returns : quantiles : Series or DataFrame
-> If q is an array, a DataFrame will be returned where the index is q, the columns are the columns of self, and the values are the quantiles.
-> If q is a float, a Series will be returned where the index is the columns of self and the values are the quantiles.
Example #1: Use quantile() function to find the value of “.2” quantile
# importing pandas as pdimport pandas as pd # Creating the dataframe df = pd.DataFrame({"A":[1, 5, 3, 4, 2], "B":[3, 2, 4, 3, 4], "C":[2, 2, 7, 3, 4], "D":[4, 3, 6, 12, 7]}) # Print the dataframedf |

Let’s use the dataframe.quantile() function to find the quantile of ‘.2’ for each column in the dataframe
# find the product over the index axisdf.quantile(.2, axis = 0) |
Выход :
Example #2: Use quantile() function to find the (.1, .25, .5, .75) qunatiles along the index axis.
# importing pandas as pdimport pandas as pd # Creating the dataframe df = pd.DataFrame({"A":[1, 5, 3, 4, 2], "B":[3, 2, 4, 3, 4], "C":[2, 2, 7, 3, 4], "D":[4, 3, 6, 12, 7]}) # using quantile() function to# find the quantiles over the index axisdf.quantile([.1, .25, .5, .75], axis = 0) |
Выход :
Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.
Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.