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")
| 3855 | ) |
| 3856 | |
| 3857 | def quantile(self, q=0.5, axis=0, numeric_only=False, method="default"): |
| 3858 | """Approximate row-wise and precise column-wise quantiles of DataFrame |
| 3859 | |
| 3860 | Parameters |
| 3861 | ---------- |
| 3862 | q : list/array of floats, default 0.5 (50%) |
| 3863 | Iterable of numbers ranging from 0 to 1 for the desired quantiles |
| 3864 | axis : {0, 1, 'index', 'columns'} (default 0) |
| 3865 | 0 or 'index' for row-wise, 1 or 'columns' for column-wise |
| 3866 | method : {'default', 'tdigest', 'dask'}, optional |
| 3867 | What method to use. By default will use dask's internal custom |
| 3868 | algorithm (``'dask'``). If set to ``'tdigest'`` will use tdigest |
| 3869 | for floats and ints and fallback to the ``'dask'`` otherwise. |
| 3870 | """ |
| 3871 | allowed_methods = ["default", "dask", "tdigest"] |
| 3872 | if method not in allowed_methods: |
| 3873 | raise ValueError("method can only be 'default', 'dask' or 'tdigest'") |
| 3874 | meta = make_meta( |
| 3875 | meta_nonempty(self._meta).quantile( |
| 3876 | q=q, numeric_only=numeric_only, axis=axis |
| 3877 | ) |
| 3878 | ) |
| 3879 | |
| 3880 | if axis == 1: |
| 3881 | if isinstance(q, list): |
| 3882 | # Not supported, the result will have current index as columns |
| 3883 | raise ValueError("'q' must be scalar when axis=1 is specified") |
| 3884 | |
| 3885 | return self.map_partitions( |
| 3886 | M.quantile, |
| 3887 | q, |
| 3888 | axis, |
| 3889 | enforce_metadata=False, |
| 3890 | meta=meta, |
| 3891 | numeric_only=numeric_only, |
| 3892 | ) |
| 3893 | |
| 3894 | if numeric_only: |
| 3895 | frame = self.select_dtypes( |
| 3896 | "number", exclude=[np.timedelta64, np.datetime64] |
| 3897 | ) |
| 3898 | else: |
| 3899 | frame = self |
| 3900 | |
| 3901 | collections = [] |
| 3902 | for _, col in frame.items(): |
| 3903 | collections.append(col.quantile(q=q, method=method)) |
| 3904 | |
| 3905 | if len(collections) > 0 and isinstance(collections[0], Scalar): |
| 3906 | return _from_scalars(collections, meta, frame.expr.columns) |
| 3907 | |
| 3908 | return concat(collections, axis=1) |
| 3909 | |
| 3910 | @derived_from(pd.DataFrame) |
| 3911 | def median(self, axis=0, numeric_only=False): |