Skip to content

.describe() for series of objects #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2497,7 +2497,7 @@ def min(self, axis=0, skipna=True):
min : Series
"""
values = self.values.copy()
if skipna:
if skipna and not issubclass(values.dtype.type, np.int_):
np.putmask(values, -np.isfinite(values), np.inf)
return Series(values.min(axis), index=self._get_agg_axis(axis))

Expand All @@ -2518,7 +2518,7 @@ def max(self, axis=0, skipna=True):
max : Series
"""
values = self.values.copy()
if skipna:
if skipna and not issubclass(values.dtype.type, np.int_):
np.putmask(values, -np.isfinite(values), -np.inf)
return Series(values.max(axis), index=self._get_agg_axis(axis))

Expand Down
21 changes: 15 additions & 6 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# pylint: disable=E1101,E1103
# pylint: disable=W0703,W0622,W0613,W0201

import collections
import csv
import itertools
import operator
Expand Down Expand Up @@ -873,12 +874,20 @@ def describe(self):
-------
desc : Series
"""
names = ['count', 'mean', 'std', 'min',
'25%', '50%', '75%', 'max']

data = [self.count(), self.mean(), self.std(), self.min(),
self.quantile(.25), self.median(), self.quantile(.75),
self.max()]
if self.dtype == object:
names = ['count', 'unique', 'top', 'freq']

objcounts = collections.Counter(self)
top, freq = objcounts.most_common(1)[0]
data = [self.count(), len(objcounts), top, freq]

else:
names = ['count', 'mean', 'std', 'min',
'25%', '50%', '75%', 'max']

data = [self.count(), self.mean(), self.std(), self.min(),
self.quantile(.25), self.median(), self.quantile(.75),
self.max()]

return Series(data, index=names)

Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2721,9 +2721,11 @@ def wrapper(x):

def test_min(self):
self._check_stat_op('min', np.min)
self._check_stat_op('min', np.min, frame=self.intframe)

def test_max(self):
self._check_stat_op('max', np.max)
self._check_stat_op('max', np.max, frame=self.intframe)

def test_mad(self):
f = lambda x: np.abs(x - x.mean()).mean()
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ def test_quantile(self):
def test_describe(self):
_ = self.series.describe()
_ = self.ts.describe()
_ = self.objSeries.describe()

def test_append(self):
appendedSeries = self.series.append(self.ts)
Expand Down