Skip to content

BUG: Groupy By #38159

Closed
Closed
@SankalpMe

Description

@SankalpMe
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

# Your code here
import pandas as pd
df = pd.DataFrame([[1,2,3],[1,4,5],[2,3,4]],columns=['a','b','c'])
grouped = df.groupby('a')
print("GROUPED:")
print(grouped) #prints  pandas.core.groupby.generic.DataFrameGroupBy no frame...

grpA = grouped.apply(lambda grp: grp[:])
print('GROUPED A:')
print(grpA) #prints grouped df.

grpB = grouped.apply(lambda grp: grp)
print('GROUPED B:')
print(grpB) #doesn't print grouped df just prints the normal df.

Current Output

GROUPED:
<pandas.core.groupby.generic.DataFrameGroupBy object at 0x1205a1a90>
GROUPED A:
a b c
a
1 0 1 2 3
1 1 4 5
2 2 2 3 4
GROUPED B:
a b c
0 1 2 3
1 1 4 5
2 2 3 4

Problem description

Why is they print(grouped) not working ?
Also why is there different output for grpA, grpB : grpA get's nicely grouped while grbB just prints the orginal df.
shouldn't df[:] and df be the same as I have used in apply function , why are they producing different output?

Expected Output

GROUPED:
<pandas.core.groupby.generic.DataFrameGroupBy object at 0x1205a1a90>
GROUPED A:
a b c
a
1 0 1 2 3
1 1 4 5
2 2 2 3 4
GROUPED B:
a b c
a
1 0 1 2 3
1 1 4 5
2 2 2 3 4

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 67a3d42
python : 3.7.7.final.0
python-bits : 64
OS : Darwin
OS-release : 20.1.0
Version : Darwin Kernel Version 20.1.0: Sat Oct 31 00:07:11 PDT 2020; root:xnu-7195.50.7~2/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8

pandas : 1.1.4
numpy : 1.19.4
pytz : 2020.4
dateutil : 2.8.1
pip : 19.2.3
setuptools : 41.2.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions