MCPcopy Create free account
hub / github.com/dask/dask / quantile

Method quantile

dask/dataframe/dask_expr/_collection.py:3827–3878  ·  view source on GitHub ↗

Approximate row-wise and precise column-wise quantiles of DataFrame Parameters ---------- q : list/array of floats, default 0.5 (50%) Iterable of numbers ranging from 0 to 1 for the desired quantiles axis : {0, 1, 'index', 'columns'} (default 0)

(self, q=0.5, axis=0, numeric_only=False, method="default")

Source from the content-addressed store, hash-verified

3825 )
3826
3827 def quantile(self, q=0.5, axis=0, numeric_only=False, method="default"):
3828 """Approximate row-wise and precise column-wise quantiles of DataFrame
3829
3830 Parameters
3831 ----------
3832 q : list/array of floats, default 0.5 (50%)
3833 Iterable of numbers ranging from 0 to 1 for the desired quantiles
3834 axis : {0, 1, 'index', 'columns'} (default 0)
3835 0 or 'index' for row-wise, 1 or 'columns' for column-wise
3836 method : {'default', 'tdigest', 'dask'}, optional
3837 What method to use. By default will use dask's internal custom
3838 algorithm (``'dask'``). If set to ``'tdigest'`` will use tdigest
3839 for floats and ints and fallback to the ``'dask'`` otherwise.
3840 """
3841 allowed_methods = ["default", "dask", "tdigest"]
3842 if method not in allowed_methods:
3843 raise ValueError("method can only be 'default', 'dask' or 'tdigest'")
3844 meta = make_meta(
3845 meta_nonempty(self._meta).quantile(
3846 q=q, numeric_only=numeric_only, axis=axis
3847 )
3848 )
3849
3850 if axis == 1:
3851 if isinstance(q, list):
3852 # Not supported, the result will have current index as columns
3853 raise ValueError("'q' must be scalar when axis=1 is specified")
3854
3855 return self.map_partitions(
3856 M.quantile,
3857 q,
3858 axis,
3859 enforce_metadata=False,
3860 meta=meta,
3861 numeric_only=numeric_only,
3862 )
3863
3864 if numeric_only:
3865 frame = self.select_dtypes(
3866 "number", exclude=[np.timedelta64, np.datetime64]
3867 )
3868 else:
3869 frame = self
3870
3871 collections = []
3872 for _, col in frame.items():
3873 collections.append(col.quantile(q=q, method=method))
3874
3875 if len(collections) > 0 and isinstance(collections[0], Scalar):
3876 return _from_scalars(collections, meta, frame.expr.columns)
3877
3878 return concat(collections, axis=1)
3879
3880 @derived_from(pd.DataFrame)
3881 def median(self, axis=0, numeric_only=False):

Calls 7

select_dtypesMethod · 0.95
make_metaFunction · 0.90
_from_scalarsFunction · 0.85
concatFunction · 0.70
quantileMethod · 0.45
map_partitionsMethod · 0.45
itemsMethod · 0.45