ValueError: Grouper for not 1-dimensional

Simplified problem

I also ran into this problem and found that it was caused by duplicate column names.

To recreate this:

df = pd.DataFrame({"foo": [1,2,3], "bar": [1,2,3]})
df.rename(columns={'foo': 'bar'}, inplace=True)

   bar  bar
0    1    1
1    2    2
2    3    3

df.groupby('bar')

ValueError: Grouper for 'bar' not 1-dimensional

Just like a lot of cryptic pandas errors, this one too stems from having two columns with the same name.

Figure out which one you want to use, rename or drop the other column and redo the operation.

Solution

Rename the columns like this

df.columns = ['foo', 'bar']

   foo  bar
0    1    1
1    2    2
2    3    3

df.groupby('bar')
<pandas.core.groupby.DataFrameGroupBy object at 0x1066dd950>

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)