-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Series.nonzero(): Returns locations, not indices #19312
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
It'd be good to clarify that the return values is the integer locations. |
What is the difference between indices and integer locations? It seems to me that the documentation is very clear. |
Indices may be the index labels, which may or may not match the positions.
…On Fri, Jan 19, 2018 at 1:28 PM, Dror Atariah ***@***.***> wrote:
What is the difference between indices and integer locations? It seems to
me that the documentation is very clear.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#19312 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABQHIoaF9A8Jb8VN_xJTMaSLWzSsexCfks5tMOzEgaJpZM4RkRWk>
.
|
Make sense. I will stress this in the documentation and add an example. See https://github.com/drorata/pandas/tree/fix-19312 |
Wait... even if the indices are not integers, the output of >>> import pandas as pd
>>> s = pd.Series([0, 3, 0, 4])
>>> s.index=['a', 'b', 'c', 'd']
>>> s.nonzero()
(array([1, 3]),)
>>> s.iloc[s.nonzero()[0]]
b 3
d 4
dtype: int64 Isn't it surprising? |
Series.iloc is for selection by integer position (and supports slicing): The label based indexer is Series.loc: |
Hi, |
|
Problem description
Documentation says
Series.nonzero(): Return the indices of the elements that are non-zero
while it actually seems to return the integer locations.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.3.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: AMD64 Family 21 Model 16 Stepping 1, AuthenticAMD
byteorder: little
LC_ALL: None
LANG: en
LOCALE: None.None
pandas: 0.21.0
pytest: None
pip: 9.0.1
setuptools: 36.5.0.post20170921
Cython: None
numpy: 1.13.3
scipy: 0.19.1
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: 1.6.3
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.1.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.9999999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: