Change language

Python | Pandas dataframe.quantile ()

The Pandas function dataframe.quantile() returns values ​​in the specified quantile along the requested axis, numpy.percentile.

Note. In each set of values, a variable that divides the frequency distribution into equal groups, each of which contains 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 "= 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 the function quantile () to find the quantile value ".2"

# import pandas as pd

import pandas as pd

 
# Create data frame

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 data frame
df

Let’s use the dataframe.quantile () function to find the quantile & # 39; .2 & # 39; for each column in the data frame.

# find product by index axis

df.quantile (. 2 , axis = 0 )

Output:

Example # 2: Use the quantile () function to find quantile () .1, .25, .5, .75) along the index axis .

# import pandas as pd

import pandas as pd

 
# Create data frame

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 the quantile function () for
# find quantiles along the index axis

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

Exit :

Shop

Gifts for programmers

Learn programming in R: courses

$FREE
Gifts for programmers

Best Python online courses for 2022

$FREE
Gifts for programmers

Best laptop for Fortnite

$399+
Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best computer for crypto mining

$499+
Gifts for programmers

Best laptop for Sims 4

$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically