You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now I want to group by Name and sum the Items, but I want the sum to be NaN if there are NaN elements. Due to a bug in pandas (#20824) I cannot simply do
which is wrong because it's skipping the NaN for Greg even though it shouldn't (hence the bug). Thus I'm using the following workaround to get the correct result:
Problem description
Consider the following data frame:
Now I want to group by
Name
and sum theItems
, but I want the sum to be NaN if there are NaN elements. Due to a bug in pandas (#20824) I cannot simply dobecause that results in:
which is wrong because it's skipping the
NaN
for Greg even though it shouldn't (hence the bug). Thus I'm using the following workaround to get the correct result:which results in the expected:
However, if we change the
Name
column to categorical then the resulting column names are wrong:which prints:
As you can see, the column that should be labelled
Name
is now calledindex
.Expected Output
The same as the non-categorical version, i.e.:
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.3.final.0
python-bits : 64
OS : Windows
OS-release : 7
machine : AMD64
processor : Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None
pandas : 0.25.1
numpy : 1.16.3
pytz : 2019.1
dateutil : 2.8.0
pip : 19.1
setuptools : 41.0.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.2.5
html5lib : None
pymysql : None
psycopg2 : 2.8.2 (dt dec pq3 ext lo64)
jinja2 : 2.10.1
IPython : 7.5.0
pandas_datareader: None
bs4 : 4.7.1
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.2.5
matplotlib : 3.0.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 0.13.0
pytables : None
s3fs : None
scipy : 1.2.1
sqlalchemy : 1.3.3
tables : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None
The text was updated successfully, but these errors were encountered: