Code Sample
df = pd.DataFrame({'A': ['bar','bar','foo', 'foo', 'bar'],
'B': ['one', 'one', 'one', 'three', 'four'],
'C': [1,2,3,4,5]})
def fun(x):
print(x)
s.groupby(['A']).apply(fun)
# result
A B C
0 bar one 1
1 bar one 2
4 bar four 5
A B C
0 bar one 1
1 bar one 2
4 bar four 5
A B C
2 foo one 3
3 foo three 4
Problem description
Why the first sub-group will be repeated?This is a bug or the designer is interested!
Expected Output
A B C
0 bar one 1
1 bar one 2
4 bar four 5
A B C
2 foo one 3
3 foo three 4
Output of pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.13.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-98-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: None.None
pandas: 0.20.1
pytest: 3.0.7
pip: 9.0.1
setuptools: 37.0.0
Cython: 0.25.2
numpy: 1.13.3
scipy: 0.19.0
xarray: None
IPython: 5.5.0
sphinx: 1.5.6
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: 1.2.1
tables: 3.3.0
numexpr: 2.6.2
feather: None
matplotlib: 2.1.0
openpyxl: 2.4.7
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 3.7.3
bs4: 4.6.0
html5lib: 0.999
sqlalchemy: 1.1.9
pymysql: None
psycopg2: 2.7.3.2 (dt dec pq3 ext lo64)
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: None
Comment From: jschendel
See the warning box at the end of the flexible apply section of the documentation.
Comment From: ghost
thank you!