Skip to content

Commit d146e1a

Browse files
committed
DOC: Improved the docstrings under pd.DataFrame
commit after checking docstring
1 parent 52cffa3 commit d146e1a

File tree

2 files changed

+78
-6
lines changed

2 files changed

+78
-6
lines changed

pandas/core/frame.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2432,7 +2432,8 @@ def eval(self, expr, inplace=False, **kwargs):
24322432
return _eval(expr, inplace=inplace, **kwargs)
24332433

24342434
def select_dtypes(self, include=None, exclude=None):
2435-
"""Return a subset of a DataFrame including/excluding columns based on
2435+
"""
2436+
Return a subset of a DataFrame including/excluding columns based on
24362437
their ``dtype``.
24372438
24382439
Parameters
@@ -2483,7 +2484,7 @@ def select_dtypes(self, include=None, exclude=None):
24832484
4 -0.9703 True 1.0
24842485
5 -1.2094 False 2.0
24852486
>>> df.select_dtypes(include='bool')
2486-
c
2487+
b
24872488
0 True
24882489
1 False
24892490
2 True

pandas/core/generic.py

+75-4
Original file line numberDiff line numberDiff line change
@@ -4232,7 +4232,8 @@ def as_matrix(self, columns=None):
42324232

42334233
@property
42344234
def values(self):
4235-
"""Numpy representation of NDFrame
4235+
"""
4236+
Return NDFrame as ndarray or ndarray-like depending on the dtype.
42364237
42374238
Notes
42384239
-----
@@ -4245,6 +4246,16 @@ def values(self):
42454246
float32. If dtypes are int32 and uint8, dtype will be upcast to
42464247
int32. By numpy.find_common_type convention, mixing int64 and uint64
42474248
will result in a flot64 dtype.
4249+
4250+
Examples
4251+
--------
4252+
>>> df = pd.DataFrame({'a': np.random.randn(2).astype('f4'),
4253+
... 'b': [True, False], 'c': [1.0, 2.0]})
4254+
>>> type(df.values)
4255+
<class 'numpy.ndarray'>
4256+
>>> df.values
4257+
array([[0.25209328532218933, True, 1.0],
4258+
[0.35383567214012146, False, 2.0]], dtype=object)
42484259
"""
42494260
self._consolidate_inplace()
42504261
return self._data.as_array(transpose=self._AXIS_REVERSED)
@@ -4260,16 +4271,76 @@ def _get_values(self):
42604271
return self.values
42614272

42624273
def get_values(self):
4263-
"""same as values (but handles sparseness conversions)"""
4274+
"""
4275+
Same as values (but handles sparseness conversions).
4276+
4277+
Returns
4278+
-------
4279+
numpy.ndaray
4280+
Numpy representation of NDFrame
4281+
4282+
Examples
4283+
--------
4284+
>>> df = pd.DataFrame({'a': np.random.randn(2).astype('f4'),
4285+
... 'b': [True, False], 'c': [1.0, 2.0]})
4286+
>>> df.get_values()
4287+
array([[0.25209328532218933, True, 1.0],
4288+
[0.35383567214012146, False, 2.0]], dtype=object)
4289+
"""
42644290
return self.values
42654291

42664292
def get_dtype_counts(self):
4267-
"""Return the counts of dtypes in this object."""
4293+
"""
4294+
Return counts of unique dtypes in this object.
4295+
4296+
Returns
4297+
-------
4298+
dtype Number of dtype
4299+
4300+
See Also
4301+
--------
4302+
dtypes : Return the dtypes in this object.
4303+
4304+
Examples
4305+
--------
4306+
>>> a = [['a', 1, 1.0], ['b', 2, 2.0], ['c', 3, 3.0]]
4307+
>>> df = pd.DataFrame(a, columns=['str', 'int', 'float'])
4308+
>>> df['int'].astype(int)
4309+
>>> df['float'].astype(float)
4310+
>>> df.get_dtype_counts()
4311+
float64 1
4312+
int64 1
4313+
object 1
4314+
dtype: int64
4315+
"""
42684316
from pandas import Series
42694317
return Series(self._data.get_dtype_counts())
42704318

42714319
def get_ftype_counts(self):
4272-
"""Return the counts of ftypes in this object."""
4320+
"""
4321+
Return counts of unique ftypes in this object.
4322+
4323+
Returns
4324+
-------
4325+
dtype Number of dtype:dense|sparse
4326+
4327+
See Also
4328+
--------
4329+
ftypes : Return
4330+
ftypes (indication of sparse/dense and dtype) in this object.
4331+
4332+
Examples
4333+
--------
4334+
>>> a = [['a', 1, 1.0], ['b', 2, 2.0], ['c', 3, 3.0]]
4335+
>>> df = pd.DataFrame(a, columns=['str', 'int', 'float'])
4336+
>>> df['int'].astype(int)
4337+
>>> df['float'].astype(float)
4338+
>>> df.get_dtype_counts()
4339+
float64:dense 1
4340+
int64:dense 1
4341+
object:dense 1
4342+
dtype: int64
4343+
"""
42734344
from pandas import Series
42744345
return Series(self._data.get_ftype_counts())
42754346

0 commit comments

Comments
 (0)