argwhere does not work with pandas Series
See original GitHub issuenp.argwhere() does not work on a pandas series in v1.18.1, whereas it works in an older version v1.17.3. Also, np.where() works on a pandas series but np.argwhere() does not.
Reproducing code example:
import numpy as np
import pandas as pd
ser = pd.Series(np.random.randn(5), index=['a', 'b', 'c', 'd', 'e'])
np.argwhere(ser < 0)
Error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<__array_function__ internals>", line 6, in argwhere
File "/Users/kramanathan/anaconda3/envs/py3.7/lib/python3.7/site-packages/numpy/core/numeric.py", line 584, in argwhere
return transpose(nonzero(a))
File "<__array_function__ internals>", line 6, in nonzero
File "/Users/kramanathan/anaconda3/envs/py3.7/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 1896, in nonzero
return _wrapfunc(a, 'nonzero')
File "/Users/kramanathan/anaconda3/envs/py3.7/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 58, in _wrapfunc
return _wrapit(obj, method, *args, **kwds)
File "/Users/kramanathan/anaconda3/envs/py3.7/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 51, in _wrapit
result = wrap(result)
File "/Users/kramanathan/anaconda3/envs/py3.7/lib/python3.7/site-packages/pandas/core/generic.py", line 1918, in __array_wrap__
return self._constructor(result, **d).__finalize__(self)
File "/Users/kramanathan/anaconda3/envs/py3.7/lib/python3.7/site-packages/pandas/core/series.py", line 292, in __init__
f"Length of passed values is {len(data)}, "
ValueError: Length of passed values is 1, index implies 5.
Numpy/Python version information:
1.18.1 3.7.4 (default, Aug 13 2019, 20:35:49)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Python pandas: Getting the locations of a value in dataframe
If you don't mind working with a NumPy array with the first column ... inside of np.argwhere , so for example say you...
Read more >numpy.argwhere — NumPy v1.24 Manual
Find the indices of array elements that are non-zero, grouped by element. Parameters: ... The output of argwhere is not suitable for indexing...
Read more >numpy.argwhere() in Python - GeeksforGeeks
numpy.argwhere() function is used to find the indices of array elements that are non-zero, grouped by element. Syntax : numpy.argwhere(arr).
Read more >pandas.Series.argmax — pandas 1.5.2 documentation
Return int position of the largest value in the Series. If the maximum is achieved in multiple locations, the first row position is...
Read more >np.argwhere: How to Use Numpy argwhere() Function
The np.argwhere() is a numpy library function used to find the indices of nonzero array elements grouped by element. The numpy argwhere() ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
yes, my pandas versions are 0.25.3 where it does not fail and 1.0.1 where it fails
My guess is your pandas version is different between the two python versions?