Skip to content

Commit 71e42a8

Browse files
coffeedjimmyTomAugspurger
authored andcommitted
DOC: update the docstring for several functions and properties (Seoul). (#20099)
1 parent 3c8d1d4 commit 71e42a8

File tree

2 files changed

+124
-21
lines changed

2 files changed

+124
-21
lines changed

pandas/core/frame.py

+21-18
Original file line numberDiff line numberDiff line change
@@ -2597,8 +2597,8 @@ def eval(self, expr, inplace=False, **kwargs):
25972597
return _eval(expr, inplace=inplace, **kwargs)
25982598

25992599
def select_dtypes(self, include=None, exclude=None):
2600-
"""Return a subset of a DataFrame including/excluding columns based on
2601-
their ``dtype``.
2600+
"""
2601+
Return a subset of the DataFrame's columns based on the column dtypes.
26022602
26032603
Parameters
26042604
----------
@@ -2636,25 +2636,27 @@ def select_dtypes(self, include=None, exclude=None):
26362636
26372637
Examples
26382638
--------
2639-
>>> df = pd.DataFrame({'a': np.random.randn(6).astype('f4'),
2639+
>>> df = pd.DataFrame({'a': [1, 2] * 3,
26402640
... 'b': [True, False] * 3,
26412641
... 'c': [1.0, 2.0] * 3})
26422642
>>> df
26432643
a b c
2644-
0 0.3962 True 1.0
2645-
1 0.1459 False 2.0
2646-
2 0.2623 True 1.0
2647-
3 0.0764 False 2.0
2648-
4 -0.9703 True 1.0
2649-
5 -1.2094 False 2.0
2644+
0 1 True 1.0
2645+
1 2 False 2.0
2646+
2 1 True 1.0
2647+
3 2 False 2.0
2648+
4 1 True 1.0
2649+
5 2 False 2.0
2650+
26502651
>>> df.select_dtypes(include='bool')
2651-
c
2652+
b
26522653
0 True
26532654
1 False
26542655
2 True
26552656
3 False
26562657
4 True
26572658
5 False
2659+
26582660
>>> df.select_dtypes(include=['float64'])
26592661
c
26602662
0 1.0
@@ -2663,14 +2665,15 @@ def select_dtypes(self, include=None, exclude=None):
26632665
3 2.0
26642666
4 1.0
26652667
5 2.0
2666-
>>> df.select_dtypes(exclude=['floating'])
2667-
b
2668-
0 True
2669-
1 False
2670-
2 True
2671-
3 False
2672-
4 True
2673-
5 False
2668+
2669+
>>> df.select_dtypes(exclude=['int'])
2670+
b c
2671+
0 True 1.0
2672+
1 False 2.0
2673+
2 True 1.0
2674+
3 False 2.0
2675+
4 True 1.0
2676+
5 False 2.0
26742677
"""
26752678

26762679
if not is_list_like(include):

pandas/core/generic.py

+103-3
Original file line numberDiff line numberDiff line change
@@ -4321,16 +4321,116 @@ def _get_values(self):
43214321
return self.values
43224322

43234323
def get_values(self):
4324-
"""same as values (but handles sparseness conversions)"""
4324+
"""
4325+
Return an ndarray after converting sparse values to dense.
4326+
4327+
This is the same as ``.values`` for non-sparse data. For sparse
4328+
data contained in a `pandas.SparseArray`, the data are first
4329+
converted to a dense representation.
4330+
4331+
Returns
4332+
-------
4333+
numpy.ndarray
4334+
Numpy representation of DataFrame
4335+
4336+
See Also
4337+
--------
4338+
values : Numpy representation of DataFrame.
4339+
pandas.SparseArray : Container for sparse data.
4340+
4341+
Examples
4342+
--------
4343+
>>> df = pd.DataFrame({'a': [1, 2], 'b': [True, False],
4344+
... 'c': [1.0, 2.0]})
4345+
>>> df
4346+
a b c
4347+
0 1 True 1.0
4348+
1 2 False 2.0
4349+
4350+
>>> df.get_values()
4351+
array([[1, True, 1.0], [2, False, 2.0]], dtype=object)
4352+
4353+
>>> df = pd.DataFrame({"a": pd.SparseArray([1, None, None]),
4354+
... "c": [1.0, 2.0, 3.0]})
4355+
>>> df
4356+
a c
4357+
0 1.0 1.0
4358+
1 NaN 2.0
4359+
2 NaN 3.0
4360+
4361+
>>> df.get_values()
4362+
array([[ 1., 1.],
4363+
[nan, 2.],
4364+
[nan, 3.]])
4365+
"""
43254366
return self.values
43264367

43274368
def get_dtype_counts(self):
4328-
"""Return the counts of dtypes in this object."""
4369+
"""
4370+
Return counts of unique dtypes in this object.
4371+
4372+
Returns
4373+
-------
4374+
dtype : Series
4375+
Series with the count of columns with each dtype.
4376+
4377+
See Also
4378+
--------
4379+
dtypes : Return the dtypes in this object.
4380+
4381+
Examples
4382+
--------
4383+
>>> a = [['a', 1, 1.0], ['b', 2, 2.0], ['c', 3, 3.0]]
4384+
>>> df = pd.DataFrame(a, columns=['str', 'int', 'float'])
4385+
>>> df
4386+
str int float
4387+
0 a 1 1.0
4388+
1 b 2 2.0
4389+
2 c 3 3.0
4390+
4391+
>>> df.get_dtype_counts()
4392+
float64 1
4393+
int64 1
4394+
object 1
4395+
dtype: int64
4396+
"""
43294397
from pandas import Series
43304398
return Series(self._data.get_dtype_counts())
43314399

43324400
def get_ftype_counts(self):
4333-
"""Return the counts of ftypes in this object."""
4401+
"""
4402+
Return counts of unique ftypes in this object.
4403+
4404+
This is useful for SparseDataFrame or for DataFrames containing
4405+
sparse arrays.
4406+
4407+
Returns
4408+
-------
4409+
dtype : Series
4410+
Series with the count of columns with each type and
4411+
sparsity (dense/sparse)
4412+
4413+
See Also
4414+
--------
4415+
ftypes : Return ftypes (indication of sparse/dense and dtype) in
4416+
this object.
4417+
4418+
Examples
4419+
--------
4420+
>>> a = [['a', 1, 1.0], ['b', 2, 2.0], ['c', 3, 3.0]]
4421+
>>> df = pd.DataFrame(a, columns=['str', 'int', 'float'])
4422+
>>> df
4423+
str int float
4424+
0 a 1 1.0
4425+
1 b 2 2.0
4426+
2 c 3 3.0
4427+
4428+
>>> df.get_ftype_counts()
4429+
float64:dense 1
4430+
int64:dense 1
4431+
object:dense 1
4432+
dtype: int64
4433+
"""
43344434
from pandas import Series
43354435
return Series(self._data.get_ftype_counts())
43364436

0 commit comments

Comments
 (0)