Have you grouped by a list of labels and been told the lengths disagree?
sales = pd.DataFrame({'region': ['North', 'South', 'North'],
'revenue': [100, 250, 175]})
sales.groupby(np.array([1, 2])).sum()
ValueError: Grouper and axis must be same length
When you group by something other than a column name, Pandas expects one group label per row. Two labels, three rows, no way to proceed.
If the labels were meant to come from a column, name it and the length takes care of itself:
sales.groupby('region').sum()
The silent version is worse
Here is the finding worth the page. A NumPy array of the wrong length raises. A Series of the wrong length does not:
sales.groupby(pd.Series([1, 2])).sum()
region revenue
1.0 North 100
2.0 South 250
Two groups, two rows, no error, and the third row of sales has vanished from the result. A Series carries an index, so Pandas aligns it against the frame's index rather than checking its length — and rows the Series does not label are dropped.
That is the same alignment rule that shows up everywhere in Pandas, and it is helpful far more often than it is harmful. But it means a length bug raises loudly with an array and produces a quietly incomplete answer with a Series. If a groupby result has fewer rows than you expect, check the length and index of whatever you grouped by.
Grouping by something computed
The usual reason to group by an array rather than a column name is a value derived on the fly. Keep it derived from the frame itself and the lengths cannot drift:
sales.groupby(sales['revenue'] > 150).sum()
or, if it needs a name in the output, assign it first:
sales.assign(big=sales['revenue'] > 150).groupby('big').sum()
The second is longer and I prefer it: the grouping key becomes part of the frame, so it survives being passed to another function and shows up in the result with a label rather than as True and False.
Grouping by several things
A list of column names groups by their combination:
sales.groupby(['region', 'quarter']).sum()
That is different from passing a list of values, which is what triggers the error. Pandas distinguishes them by checking whether the entries are column names, so a typo in one name changes the meaning of the whole argument — and usually produces a KeyError rather than this message.
The mistakes I see most often
Grouping by a filtered column. sales.groupby(other_df['region']) aligns on index and drops whatever does not match. If the two frames are not the same rows, the result is wrong rather than an error.
Using a list where a column name was meant. groupby([1, 2]) is read as two column names, and raises KeyError: 1.
Reading "axis" as something to configure. Here it just means the rows of your frame.
Practice
See groupby in Pandas for grouping generally, and Grouper in Pandas for grouping by time period.