diff --git a/pandas/core/frame.py b/pandas/core/frame.py index a66d00fff9714..4b3db21dc87c0 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -550,8 +550,17 @@ def _get_axes(N, K, index=index, columns=columns): @property def axes(self): """ - Return a list with the row axis labels and column axis labels as the - only members. They are returned in that order. + Return a list representing the axes of the DataFrame. + + It has the row axis labels and column axis labels as the only members. + They are returned in that order. + + Examples + -------- + >>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]}) + >>> df.axes + [RangeIndex(start=0, stop=2, step=1), Index(['coll', 'col2'], + dtype='object')] """ return [self.index, self.columns] @@ -559,6 +568,21 @@ def axes(self): def shape(self): """ Return a tuple representing the dimensionality of the DataFrame. + + See Also + -------- + ndarray.shape + + Examples + -------- + >>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]}) + >>> df.shape + (2, 2) + + >>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4], + ... 'col3': [5, 6]}) + >>> df.shape + (2, 3) """ return len(self.index), len(self.columns) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a893b2ba1a189..ff65c88970b86 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -457,12 +457,49 @@ def axes(self): @property def ndim(self): - """Number of axes / array dimensions""" + """ + Return an int representing the number of axes / array dimensions. + + Return 1 if Series. Otherwise return 2 if DataFrame. + + See Also + -------- + ndarray.ndim + + Examples + -------- + >>> s = pd.Series({'a': 1, 'b': 2, 'c': 3}) + >>> s.ndim + 1 + + >>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]}) + >>> df.ndim + 2 + """ return self._data.ndim @property def size(self): - """number of elements in the NDFrame""" + """ + Return an int representing the number of elements in this object. + + Return the number of rows if Series. Otherwise return the number of + rows times number of columns if DataFrame. + + See Also + -------- + ndarray.size + + Examples + -------- + >>> s = pd.Series({'a': 1, 'b': 2, 'c': 3}) + >>> s.size + 3 + + >>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]}) + >>> df.size + 4 + """ return np.prod(self.shape) @property