We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
import pandas as pd import numpy as np df = pd.DataFrame({'ind':[np.nan,np.nan,'a','a'],'col':[0,1,2,3]}).set_index('ind') df.sum(level='ind')
results in
col ind a 5
df.sum ignores rows where any index column contains a np.nan.
col ind NaN 1 1.0 5
pd.show_versions()
commit: None python: 3.6.6.final.0 python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: byteorder: little LC_ALL: None LANG: en_GB.UTF-8 LOCALE: None.None
pandas: 0.24.2 pytest: None pip: 19.0.3 setuptools: 41.0.1 Cython: 0.28.4 numpy: 1.15.4 scipy: 1.2.1 pyarrow: 0.14.0 xarray: None IPython: 7.5.0 sphinx: 1.7.5 patsy: 0.5.0 dateutil: 2.8.0 pytz: 2018.5 blosc: None bottleneck: None tables: None numexpr: None feather: None matplotlib: 2.2.2 openpyxl: None xlrd: None xlwt: None xlsxwriter: None lxml.etree: None bs4: None html5lib: 1.0.1 sqlalchemy: None pymysql: None psycopg2: None jinja2: 2.10 s3fs: None fastparquet: 0.3.2 pandas_gbq: None pandas_datareader: None gcsfs: None
The text was updated successfully, but these errors were encountered:
Thanks for the report. sum(level=...) uses groupby internally, so this is most likely the same as #3729. I'll add your note as a comment over there.
sum(level=...)
Sorry, something went wrong.
This still happens in 1.2.4 and master as of May 2021. It should probably be reopened. I will try to implement a fix.
master
Ah, no, it is fixed, just need to do dropna=False in the groupby().
dropna=False
No branches or pull requests
Code Sample
results in
Problem description
df.sum ignores rows where any index column contains a np.nan.
Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.6.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor:
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: None.None
pandas: 0.24.2
pytest: None
pip: 19.0.3
setuptools: 41.0.1
Cython: 0.28.4
numpy: 1.15.4
scipy: 1.2.1
pyarrow: 0.14.0
xarray: None
IPython: 7.5.0
sphinx: 1.7.5
patsy: 0.5.0
dateutil: 2.8.0
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.2.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: None
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: 0.3.2
pandas_gbq: None
pandas_datareader: None
gcsfs: None
The text was updated successfully, but these errors were encountered: