Skip to content
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

BUG: Groupy By #38159

Closed
3 tasks done
SankalpMe opened this issue Nov 29, 2020 · 3 comments
Closed
3 tasks done

BUG: Groupy By #38159

SankalpMe opened this issue Nov 29, 2020 · 3 comments
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@SankalpMe
Copy link

SankalpMe commented Nov 29, 2020

  • 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

@SankalpMe SankalpMe added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 29, 2020
@phofl
Copy link
Member

phofl commented Nov 29, 2020

Hi, thanks for your report. This is not a bug. The DataFrameGroupBy object has no real __repr__ method. You could maybe relabel your issue to a featur request?

@SankalpMe
Copy link
Author

It is fine that __repr__ is not implemented , my issue is with the apply function, why are there two different outputs for the same lambda fn with just different syntax...

@rhshadrach
Copy link
Member

The difference in output is a duplicate of #22546

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

3 participants