A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pandas-dev/pandas/issues/55951 below:

DataFrameGroupBy.value_counts incorrect sorting · Issue #55951 · pandas-dev/pandas · GitHub

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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4