Skip to content

Commit 3ee7ba3

Browse files
yeongseonjorisvandenbossche
authored andcommitted
DOC: update the axes, shape, dim and size property docstring (#20101)
1 parent df87fd3 commit 3ee7ba3

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
@@ -554,15 +554,39 @@ def _get_axes(N, K, index=index, columns=columns):
554554
@property
555555
def axes(self):
556556
"""
557-
Return a list with the row axis labels and column axis labels as the
558-
only members. They are returned in that order.
557+
Return a list representing the axes of the DataFrame.
558+
559+
It has the row axis labels and column axis labels as the only members.
560+
They are returned in that order.
561+
562+
Examples
563+
--------
564+
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
565+
>>> df.axes
566+
[RangeIndex(start=0, stop=2, step=1), Index(['coll', 'col2'],
567+
dtype='object')]
559568
"""
560569
return [self.index, self.columns]
561570

562571
@property
563572
def shape(self):
564573
"""
565574
Return a tuple representing the dimensionality of the DataFrame.
575+
576+
See Also
577+
--------
578+
ndarray.shape
579+
580+
Examples
581+
--------
582+
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
583+
>>> df.shape
584+
(2, 2)
585+
586+
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4],
587+
... 'col3': [5, 6]})
588+
>>> df.shape
589+
(2, 3)
566590
"""
567591
return len(self.index), len(self.columns)
568592

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)