Problem 1: Grouper for is not 1-dimensional
I was writing a nice little script in pandas where I wanted to group some data using some identifier columns. And then suddenly the error popped in the console was: Grouper for Id is not 1-dimensional. And I started investigating for it.
Solution:
This error comes if there are multiple copies of the same grouper column. In that case, you will find this error.
grouper for bar is not 1-dimensional: source: stackoverflowProblem 2: unhashable type: numpy.ndarray
This is a more generalized type of error. There are multiple instances where this error occurs; including when you try to treat a numpy ndarray object as a value or a string type object and so on. I encountered this problem when I tried to group a bunch of values in which a column contained arrays as entries. If your pandas dataframe contains array or np.ndarray as values of single cells, then this dataframe can not be further used for other different actions even like drop_duplicates. But this is not easily visible. Often array will be entered as the value in your dataframe cells by mistake and then on later lines of codes, you will find this error.
The solution is here to find out where did you enter the array values in the dataframe and then turning the array into a single integer or string type object. i.e. if your cell value is currently array([0.628]) then you should use array.values[0] which will give you 0.628. So this is how you can solve this problem. Other types of problems, i.e. normally trying to take array[0] from a n-dimensional array or some more explicit errors also can lead to this issue. Here is a link to stack exchange for the same issue.
Comments
Post a Comment