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

Method quantile

dask/dataframe/dask_expr/_collection.py:3829–3880  ·  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

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