Skip to content

Commit 06130c6

Browse files
committed
ENH: rename histogram->value_counts and sort descending, GH #265
1 parent e7b36bc commit 06130c6

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

pandas/core/series.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -592,20 +592,21 @@ def _count_level(self, level):
592592

593593
return Series(result, index=level_index)
594594

595-
def histogram(self):
595+
def value_counts(self):
596596
"""
597-
Returns Series containing counts of unique values. The result Series's
598-
index will be the sorted unique values
597+
Returns Series containing counts of unique values. The resulting Series
598+
will be in descending order so that the first element is the most
599+
frequently-occurring element
599600
600601
Returns
601602
-------
602-
histogram : Series
603+
counts : Series
603604
"""
604605
from collections import defaultdict
605606
counter = defaultdict(lambda: 0)
606607
for value in self.values:
607608
counter[value] += 1
608-
return Series(counter)
609+
return Series(counter).order(ascending=False)
609610

610611
def sum(self, axis=0, dtype=None, out=None, skipna=True):
611612
"""

pandas/tests/test_series.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -759,14 +759,14 @@ def test_count(self):
759759

760760
self.assertEqual(self.ts.count(), np.isfinite(self.ts).sum())
761761

762-
def test_histogram(self):
763-
s = Series(['a', 'b', 'b', 'b', 'a', 'c', 'd', 'd', 'a'])
764-
hist = s.histogram()
765-
expected = Series([3, 3, 1, 2], index=['a', 'b', 'c', 'd'])
762+
def test_value_counts(self):
763+
s = Series(['a', 'b', 'b', 'b', 'b', 'a', 'c', 'd', 'd', 'a'])
764+
hist = s.value_counts()
765+
expected = Series([4, 3, 2, 1], index=['b', 'a', 'd', 'c'])
766766
assert_series_equal(hist, expected)
767767

768768
s = Series({})
769-
hist = s.histogram()
769+
hist = s.value_counts()
770770
expected = Series([])
771771
assert_series_equal(hist, expected)
772772

0 commit comments

Comments
 (0)