-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Gropuby using pd.Series.mode throws error when by
column contains values with same starting value
#29635
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
Comments
This bug also occurs even in this situation where the names have no overlap: df2 = pd.DataFrame({
"Name" : ['A', 'A', 'B'],
"Credit" : [1200, 1300, 900],
"Mood" : ['sad', 'happy', 'happy']
})
aggrFDColumnDetails = {
'Mood':pd.Series.mode,
'Credit':'sum'
}
df2.groupby(['Name']).agg(aggrFDColumnDetails) But this works: df2 = pd.DataFrame({
"Name" : ['B', 'A', 'B'],
"Credit" : [1200, 1300, 900],
"Mood" : ['sad', 'happy', 'happy']
})
aggrFDColumnDetails = {
'Mood':pd.Series.mode,
'Credit':'sum'
}
df2.groupby(['Name']).agg(aggrFDColumnDetails) And this works: df2 = pd.DataFrame({
"Name" : ['B', 'B', 'A'],
"Credit" : [1200, 1300, 900],
"Mood" : ['sad', 'happy', 'happy']
})
aggrFDColumnDetails = {
'Mood':pd.Series.mode,
'Credit':'sum'
}
df2.groupby(['Name']).agg(aggrFDColumnDetails) I actually tried several combinations of what labels are where and some work and some don't. Installed versions``` INSTALLED VERSIONS ------------------ commit : None python : 3.7.4.final.0 python-bits : 64 OS : Darwin OS-release : 18.7.0 machine : x86_64 processor : i386 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8pandas : 0.25.3
|
I suppose this works on master now. Could use a test
|
take |
take |
Groupby with pd.Series.mode throws error, if
by
values starts with a value from previous row.Problem description
When I execute the above code I got error
If I change the third name to John instead of Thomas John, it works as expected. ie The following code works.
Note: We receive a lot of issues on our GitHub tracker, so it is very possible that your issue has been posted before. Please check first before submitting so that we do not have to handle and close duplicates!
Note: Many problems can be resolved by simply upgrading
pandas
to the latest version. Before submitting, please check if that solution works for you. If possible, you may want to check ifmaster
addresses this issue, but that is not necessary.For documentation-related issues, you can check the latest versions of the docs on
master
here:https://pandas-docs.github.io/pandas-docs-travis/
If the issue has not been resolved there, go ahead and file it in the issue tracker.
Expected Output
Groupby should work, even if first letters of column values are same
Output of
pd.show_versions()
[paste the output of
pd.show_versions()
here below this line]INSTALLED VERSIONS
commit: None
python: 2.7.16.final.0
python-bits: 64
OS: Darwin
OS-release: 19.0.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: None.None
pandas: 0.23.3
pytest: None
pip: 10.0.1
setuptools: 40.0.0
Cython: None
numpy: 1.14.5
scipy: 0.13.0b1
pyarrow: None
xarray: None
IPython: 5.7.0
sphinx: None
patsy: None
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.2.2
openpyxl: None
xlrd: 1.1.0
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: