Skip to content

Groupby.apply has issues with printing command #25450

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
Pferdow30 opened this issue Feb 26, 2019 · 1 comment
Closed

Groupby.apply has issues with printing command #25450

Pferdow30 opened this issue Feb 26, 2019 · 1 comment
Labels
Duplicate Report Duplicate issue or pull request

Comments

@Pferdow30
Copy link

Code Sample, a copy-pastable example if possible

>>>import pandas as pd

>>>df = pd.DataFrame(data=[[1,2], [3, 4], [5, 6]], index=[10, 20, 30])
>>>out = df.groupby(level=0).apply(lambda x: print(x))

Problem description

When print is used within the groupby.apply, it seems that the function is applied to the first index twice. I am not sure if this behaviour is due to print function, or it actually occurs for any given function. The issue may not seem to be a big deal at first; however, when groupby.apply is combined with multiprocessing framework, it hampers the efficiency and speedup of the code.

Output:

    0  1
10  1  2
    0  1
10  1  2
    0  1
20  3  4
    0  1
30  5  6

Expected Output

    0  1
10  1  2
    0  1
20  3  4
    0  1
30  5  6

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.6.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 94 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: en
LOCALE: None.None

pandas: 0.23.4
pytest: 3.8.2
pip: 19.0.2
setuptools: 40.4.3
Cython: 0.28.5
numpy: 1.14.2
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 7.0.1
sphinx: 1.8.1
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: 1.2.1
tables: 3.4.4
numexpr: 2.6.8
feather: None
matplotlib: 3.0.0
openpyxl: 2.5.8
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.1.1
lxml: 4.2.5
bs4: 4.6.3
html5lib: 1.0.1
sqlalchemy: 1.2.12
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@WillAyd
Copy link
Member

WillAyd commented Feb 26, 2019

Thanks for the report but closing as this is a duplicate of #2936

@WillAyd WillAyd closed this as completed Feb 26, 2019
@WillAyd WillAyd added the Duplicate Report Duplicate issue or pull request label Feb 26, 2019
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
Projects
None yet
Development

No branches or pull requests

2 participants