-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Groupby + sum by multiple columns on an empty DataFrame drops list of columns #15106
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
so to simplify
if you would like to trace and submit a PR to fix would be great! |
As a pointer, this is probably related to our automatically dropping nuisance columns (non-numeric cols like In [74]: pd.DataFrame([], columns=["A", "B", "C"]).astype(np.int64).groupby(['A', 'B']).sum().reset_index().columns.tolist()
Out[74]: ['A', 'B', 'C'] I wonder if this means it's not actually a bug? We are "correctly" dropping an object column after all. |
so this is a special case on
which 'works' on The reason for this is the fallback to So this is 'correct'. Though not helpful. |
Agreed with @jreback. https://github.com/pandas-dev/pandas/blob/master/pandas/core/groupby.py#L1031
https://github.com/pandas-dev/pandas/blob/master/pandas/core/groupby.py#L123
|
@chrisaycock yeah I tried to fix this at some point. The issue is that we rely on |
It is not consistent more generally with
|
Any news? I have @valentas-kurauskas 's issue. |
The problem @valentas-kurauskas and @kuraga reported seems to be that, since the dataframe is empty, the function passed to |
The simplified version of OP's report seems to work now. Could use a test
|
Code Sample
Problem description
As the original list of columns is lost in the second case, I have to handle empty data frames differently, or add columns back by myself, both of which are inconvenient.
Expected Output
The list of columns is expected to be equal to the original one from data frame
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 2.7.12.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-57-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: None.None
pandas: 0.19.1
nose: 1.3.7
pip: 9.0.1
setuptools: 28.8.0
Cython: None
numpy: 1.11.2
scipy: None
statsmodels: None
xarray: None
IPython: 5.1.0
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2016.7
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: 0.9.2
apiclient: None
sqlalchemy: 1.1.4
pymysql: None
psycopg2: 2.6.2 (dt dec pq3 ext lo64)
jinja2: 2.8
boto: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: