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/10138 below:

groupby.apply for Categorical groupers should preserve categories (like .agg) · Issue #10138 · pandas-dev/pandas · GitHub

from SO

missing = pd.Categorical(list('aaa'), categories=['a', 'b'])
dense = pd.Categorical(list('abc'))
values = np.arange(len(dense))
df = pd.DataFrame({'missing': missing, 'dense': dense, 'values': values})

grouped = df.groupby(['missing', 'dense'])

# does reindex output for missing categories
grouped.mean()
grouped.agg(np.mean)

# does not reindex the output for the missing categories
grouped.apply(lambda chunk: np.mean(chunk))

So the _wrap_applied_output need a call to _reindex_output as a post-processing step.


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