-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: When agg or reset_index to grouped DF, insert function causes ValueError. #20566
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
What is the expected result of your code samples? |
For Case 1,
or
For Case2,
or
|
Your problem is that you are trying to group and aggregate the same column, which doesn't make sense. What you are looking for is below: In [13]: df.groupby('a', as_index=False).agg({'b': 'count'})
Out[13]:
a b
0 1 3
1 2 3
2 3 3 |
Thanks. So this isn't a bug. My mistake. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code Sample, a copy-pastable example if possible
Case 1
Case 2
It returns "ValueError: cannot insert a, already exists" for both caes.
Problem description
So far, I could found 2 functions which calls "insert" function without "allow_duplicates=True" option.
One is in "def _insert_inaxis_grouper_inplace" from "pandas/core/groupby.py"
and another is in "def reset_index" from "pandas/core/frame.py"
For both cases, it result in ValueError as I wrote in Code section.
Expected Output
I think for both cases it should at least return some kind of dataframe without returning ValueError.
My concern is
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.4.final.0
python-bits: 64
OS: Linux
OS-release: 4.8.0-53-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: ja_JP.UTF-8
LOCALE: ja_JP.UTF-8
pandas: 0.22.0
pytest: 3.5.0
pip: 9.0.3
setuptools: 39.0.1
Cython: 0.28.1
numpy: 1.14.2
scipy: 1.0.1
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: 1.7.2
patsy: 0.5.0
dateutil: 2.7.2
pytz: 2018.3
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.4
feather: None
matplotlib: 2.2.2
openpyxl: 2.5.1
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.2
lxml: 4.2.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.5
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: