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

Already on GitHub? Sign in to your account

.describe() for series of objects #241

Closed
wants to merge 4 commits into
from
View
@@ -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))
@@ -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))
View
@@ -5,6 +5,7 @@
# pylint: disable=E1101,E1103
# pylint: disable=W0703,W0622,W0613,W0201
+import collections
import csv
import itertools
import operator
@@ -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)
@@ -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()
@@ -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)