Skip to content

groupby(..).apply() has inconsistent behavior when there is only one group #13121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Tracked by #13056
smoofra opened this issue May 9, 2016 · 1 comment
Closed
Tracked by #13056
Labels
Duplicate Report Duplicate issue or pull request Groupby Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@smoofra
Copy link

smoofra commented May 9, 2016

Code Sample, a copy-pastable example if possible

df = pd.DataFrame({'a':['foo', 'foo', 'bar'], 'b':[1,1,1]}).set_index('a')
def f(df):
    print '============'
    print df
    print
    print(pd.DataFrame(df.groupby(level='a').apply(lambda df: df['b'].cumsum())))

f(df)
f(df[df.index == 'foo'])

Actual Output

============
     b
a     
foo  1
foo  1
bar  1

         b
a   a     
bar bar  1
foo foo  1
    foo  2
============
     b
a     
foo  1
foo  1

a    foo  foo
a            
foo    1    2

Expected Output

============
     b
a     
foo  1
foo  1
bar  1

         b
a   a     
bar bar  1
foo foo  1
    foo  2
============
     b
a     
foo  1
foo  1

         b
a   a     
foo foo  1
    foo  2


output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 2.7.10.final.0
python-bits: 64
OS: Darwin
OS-release: 15.5.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.17.1
nose: 1.3.4
pip: 8.1.1
setuptools: 18.0.1
Cython: None
numpy: 1.9.2
scipy: 0.15.1
statsmodels: 0.6.1
IPython: 4.0.0
sphinx: None
patsy: 0.4.1
dateutil: 2.2
pytz: 2014.10
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.4.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.12
pymysql: None
psycopg2: None
Jinja2: None

@jreback
Copy link
Contributor

jreback commented May 9, 2016

tracked in #13056

@jreback jreback closed this as completed May 9, 2016
@jreback jreback added Groupby Reshaping Concat, Merge/Join, Stack/Unstack, Explode Duplicate Report Duplicate issue or pull request labels May 9, 2016
@jreback jreback added this to the No action milestone May 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request Groupby Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

2 participants