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

Method quantile

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

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