Hướng dẫn dùng nearest panda python

Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas dataframe.quantile[] function return values at the given quantile over requested axis, a numpy.percentile. Note : In each of any set of values of a variate which divide a frequency distribution into equal groups, each containing the same fraction of the total population.

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 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 

Python3

import pandas as pd

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]}]

df

 

Let’s use the dataframe.quantile[] function to find the quantile of ‘.2’ for each column in the dataframe 

Python3

df.quantile[.2, axis = 0]

Output :

 

Example #2: Use quantile[] function to find the [.1, .25, .5, .75] quantiles along the index axis. 

Python3

import pandas as pd

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]}]

df.quantile[[.1, .25, .5, .75], axis = 0]

Output :


Chủ Đề