How to make grouper and axis the same length?

十年热恋 提交于 2019-12-06 12:48:00

The problem is that you're grouping by (effectively) a list of empty list ([[]]). Because you have name = [] earlier and then you wrap that in a list as well.

If you want to group on a single column (called 'HurricaneName'), you should do something like:

for name, group in df.groupby('HurricaneName'):

However, if you want to group on multiple columns, then you need to pass a list:

for name, group in df.groupby(['HurricaneName', 'Year'])

If you want to put it in a variable like you have, you can do it like this:

col_name = 'State'

for name, group in df.groupby([col_name]):

ValueError: Grouper and axis must be same length

This can occur if you are using double brackets in the groupby argument.

(I posted this since it is the top result on Google).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!