Skip to content
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

BUG?: value_counts(normalize=True) normalizes over all observations including NaN. #12558

Closed
nickeubank opened this issue Mar 8, 2016 · 1 comment
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations
Milestone

Comments

@nickeubank
Copy link
Contributor

By default, value_counts ignores missing values. To get them displayed, one must add the option dropna=False. But when one normalizes, they are entering into the denominator even when dropna=True.

Code Sample, a copy-pastable example if possible

s = pd.Series([1,2,3,np.nan, np.nan, np.nan])
s.value_counts(normalize=True)

0.1667
0.1667
0.1667

Expected Output

0.333
0.333
0.333

output of pd.show_versions()

pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.4.4.final.0
python-bits: 64
OS: Darwin
OS-release: 15.3.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.17.1
nose: 1.3.7
pip: 8.1.0
setuptools: 20.2.2
Cython: 0.23.4
numpy: 1.10.4
scipy: 0.16.1
statsmodels: None
IPython: 4.0.1
sphinx: 1.3.1
patsy: 0.4.0
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: 1.0.0
tables: 3.2.2
numexpr: 2.4.4
matplotlib: 1.4.3
openpyxl: 2.2.6
xlrd: 0.9.4
xlwt: 1.0.0
xlsxwriter: 0.7.7
lxml: 3.4.4
bs4: 4.4.1
html5lib: 0.999
httplib2: None
apiclient: None
sqlalchemy: 1.0.9
pymysql: None
psycopg2: None
Jinja2: 2.8

@nickeubank nickeubank changed the title BUG?: value_counts(normalize=True) normalizes over all observations including NaN. BUG?: value_counts(normalize=True) normalizes over all observations including NaN. Mar 8, 2016
@jreback
Copy link
Contributor

jreback commented Mar 8, 2016

yeh, looks like its not respecting dropna

In [3]: s.value_counts(normalize=True,dropna=False)
Out[3]: 
NaN     0.500000
 3.0    0.166667
 2.0    0.166667
 1.0    0.166667
dtype: float64

In [4]: s.value_counts(normalize=True,dropna=True)
Out[4]: 
3.0    0.166667
2.0    0.166667
1.0    0.166667
dtype: float64

@jreback jreback added Bug Difficulty Novice Numeric Operations Arithmetic, Comparison, and Logical operations labels Mar 8, 2016
@jreback jreback added this to the Next Major Release milestone Mar 8, 2016
@jreback jreback modified the milestones: 0.18.1, Next Major Release Mar 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants