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

groupby drops columns if the column name is the same as the grouper · Issue #8112 · pandas-dev/pandas · GitHub

>>> df = pd.DataFrame(np.random.randint(1, 9, (2, 3)), columns=['jim', 'joe', 'jolie'])
>>> df
   jim  joe  jolie
0    4    7      8
1    7    8      3
>>> ts = df['joe'] * 0
>>> ts.name
'joe'
>>> gr = df.groupby(ts)
>>> gr.nth(0)  # this invokes _set_selection_from_grouper internally
     jim  jolie
joe
7      4      8
>>> gr.apply(sum)  # joe column is gone
     jim  jolie
joe
0     11     11

whereas:

>>> df.groupby(ts).apply(sum)
     jim  joe  jolie
joe
0     11   15     11

What happens is that this line removes the column from selection if it has the same name as the grouper.


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