Skip to content

Commit 75d6eb7

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

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

pandas/core/frame.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,15 +550,35 @@ 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+
Examples
573+
--------
574+
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
575+
>>> df.shape
576+
(2, 2)
577+
578+
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4],
579+
... 'col3': [5, 6]})
580+
>>> df.shape
581+
(2, 3)
562582
"""
563583
return len(self.index), len(self.columns)
564584

pandas/core/generic.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,12 +457,41 @@ 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+
Examples
466+
--------
467+
>>> s = pd.Series({'a': 1, 'b': 2, 'c': 3})
468+
>>> s.ndim
469+
1
470+
471+
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
472+
>>> df.ndim
473+
2
474+
"""
461475
return self._data.ndim
462476

463477
@property
464478
def size(self):
465-
"""number of elements in the NDFrame"""
479+
"""
480+
Return an int representing the number of elements in this object.
481+
482+
Return the number of rows if Series. Otherwise return the number of
483+
rows times number of columns if DataFrame.
484+
485+
Examples
486+
--------
487+
>>> s = pd.Series({'a': 1, 'b': 2, 'c': 3})
488+
>>> s.size
489+
3
490+
491+
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
492+
>>> df.size
493+
4
494+
"""
466495
return np.prod(self.shape)
467496

468497
@property

0 commit comments

Comments
 (0)