Error Indexing DafaFrame with a 0-d array
See original GitHub issue>>> df = pd.DataFrame([[1, 2], [3, 4]], columns=['a', 'b'])
>>> ar = np.array(0)
>>> df.iloc[ar]
Traceback (most recent call last):
...
...
File "/home/float2/Documents/Python/Pandas/pandas/pandas/core/indexes/base.py", line 529, in _shallow_copy_with_infer
if not len(values) and 'dtype' not in kwargs:
TypeError: object of type 'numpy.int64' has no len()
A 0-d array passes this check cause it is an Iterable. But later, when len() is called on, TypeError is raised. It would be nice to implement PEP 357 to prevent this error. The matter has been raised at PyTorch project. #9237
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:29 (26 by maintainers)
Top Results From Across the Web
Uniform way of using array indexing for 0D & 1D numpy arrays
The problem here is that value is of type numpy. ndarray , but since it's a 0-d array, numpy. cos returns a numpy....
Read more >Accessing Data Along Multiple Dimensions in an Array
Introduce the indexing and slicing scheme for accessing a multi-dimensional array's contents. We will encounter arrays of varying dimensionalities: # A 0-D ......
Read more >Version 0.18.1 (May 3, 2016) — pandas 1.4.3 documentation
Bug in SparseArray[] indexing with tuples are not handled properly (GH12966) ... in DataFrame.to_json when attempting to serialise 0d array (GH11299).
Read more >NumPy Creating Arrays - W3Schools
We can create a NumPy ndarray object by using the array() function. ... 0-D arrays, or Scalars, are the elements in an array....
Read more >Only size-1 arrays can be converted to Python scalars
This error occurs most often when you attempt to use np.int() to convert a NumPy array of float values to an array of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop 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
Top GitHub Comments
@tamuhey issues are closed when the corresponding PR is actually merged
this is a duplicate of #24919 and closed by #24924