Skip to content

Commit f7c6455

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

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

pandas/core/frame.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,15 +550,33 @@ 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 row axis labels and column axis labels
554+
as the only members. They are returned in that order.
555+
556+
Examples
557+
--------
558+
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
559+
>>> df.axes
560+
[RangeIndex(start=0, stop=2, step=1), Index(['coll', 'col2'],
561+
dtype='object')]
555562
"""
556563
return [self.index, self.columns]
557564

558565
@property
559566
def shape(self):
560567
"""
561568
Return a tuple representing the dimensionality of the DataFrame.
569+
570+
Examples
571+
--------
572+
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
573+
>>> df.shape
574+
(2, 2)
575+
576+
>>> df = pd.DataFrame({'col0': [1, 2, 3], 'col2': [4, 5, 6],
577+
... 'col3': [7, 8, 9]})
578+
>>> df.shape
579+
(3, 3)
562580
"""
563581
return len(self.index), len(self.columns)
564582

pandas/core/generic.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,12 +457,39 @@ 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+
Examples
464+
--------
465+
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
466+
>>> df.ndim
467+
2
468+
469+
>>> df = pd.DataFrame({'col1': [1, 2, 3], 'col2': [4, 5, 6],
470+
... 'col3': [7, 8, 9]})
471+
>>> df.ndim
472+
2
473+
"""
461474
return self._data.ndim
462475

463476
@property
464477
def size(self):
465-
"""number of elements in the NDFrame"""
478+
"""
479+
Return a numpy.int64 representing the number of elements
480+
in this object.
481+
482+
Examples
483+
--------
484+
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
485+
>>> df.size
486+
4
487+
488+
>>> df = pd.DataFrame({'col1': [1, 2, 3], 'col2': [4, 5, 6],
489+
... 'col3': [7, 8, 9]})
490+
>>> df.size
491+
9
492+
"""
466493
return np.prod(self.shape)
467494

468495
@property

0 commit comments

Comments
 (0)