-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed
Labels
AlgosNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffBugGroupby
Description
value_counts does not respect sort=False
from groupby:
df = pd.DataFrame({'a': [2, 1, 1], 'b': [3, 4, 3]})
gb = df.groupby('a', sort=False)
result = gb.value_counts()
print(result)
# a b
# 1 4 1
# 3 1
# 2 3 1
# Name: count, dtype: int64
In the above, the groups should appear with a=2
first and a = 1
second.
If the columns of your DataFrame are integers, the method may sort by these instead.
df = pd.DataFrame({'a': [2, 1, 1], 0: [3, 4, 3]})
gb = df.groupby('a', sort=False)
result = gb.value_counts()
print(result)
# a 0
# 2 3 1
# 1 3 1
# 4 1
# Name: count, dtype: int64
Metadata
Metadata
Assignees
Labels
AlgosNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffBugGroupby