Skip to content

Commit 6322586

Browse files
committed
DOC: Improved the docstrings of NDFrame
This change includes the following property axes, shape, ndim, size
1 parent 52cffa3 commit 6322586

File tree

2 files changed

+65
-4
lines changed

2 files changed

+65
-4
lines changed

pandas/core/frame.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,15 +550,39 @@ def _get_axes(N, K, index=index, columns=columns):
550550
@property
551551
def axes(self):
552552
"""
553-
Return a list with the row axis labels and column axis labels as the
554-
only members. They are returned in that order.
553+
Return a list representing the axes of the DataFrame.
554+
555+
It has the row axis labels and column axis labels as the only members.
556+
They are returned in that order.
557+
558+
Examples
559+
--------
560+
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
561+
>>> df.axes
562+
[RangeIndex(start=0, stop=2, step=1), Index(['coll', 'col2'],
563+
dtype='object')]
555564
"""
556565
return [self.index, self.columns]
557566

558567
@property
559568
def shape(self):
560569
"""
561570
Return a tuple representing the dimensionality of the DataFrame.
571+
572+
See Also
573+
--------
574+
ndarray.shape
575+
576+
Examples
577+
--------
578+
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
579+
>>> df.shape
580+
(2, 2)
581+
582+
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4],
583+
... 'col3': [5, 6]})
584+
>>> df.shape
585+
(2, 3)
562586
"""
563587
return len(self.index), len(self.columns)
564588

pandas/core/generic.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,12 +457,49 @@ def axes(self):
457457

458458
@property
459459
def ndim(self):
460-
"""Number of axes / array dimensions"""
460+
"""
461+
Return an int representing the number of axes / array dimensions.
462+
463+
Return 1 if Series. Otherwise return 2 if DataFrame.
464+
465+
See Also
466+
--------
467+
ndarray.ndim
468+
469+
Examples
470+
--------
471+
>>> s = pd.Series({'a': 1, 'b': 2, 'c': 3})
472+
>>> s.ndim
473+
1
474+
475+
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
476+
>>> df.ndim
477+
2
478+
"""
461479
return self._data.ndim
462480

463481
@property
464482
def size(self):
465-
"""number of elements in the NDFrame"""
483+
"""
484+
Return an int representing the number of elements in this object.
485+
486+
Return the number of rows if Series. Otherwise return the number of
487+
rows times number of columns if DataFrame.
488+
489+
See Also
490+
--------
491+
ndarray.size
492+
493+
Examples
494+
--------
495+
>>> s = pd.Series({'a': 1, 'b': 2, 'c': 3})
496+
>>> s.size
497+
3
498+
499+
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
500+
>>> df.size
501+
4
502+
"""
466503
return np.prod(self.shape)
467504

468505
@property

0 commit comments

Comments
 (0)