Home > Net >  Python - groupby mutiple columns - ValueError: Grouper and axis must be same length
Python - groupby mutiple columns - ValueError: Grouper and axis must be same length

Time:11-19

I have this dataframe which has exactly 2 columns. I need to know the frequency of each pair of data.

enter image description here

I saw this method in Stack:

base_plot2 = base_plot.groupby(["pred", col_y]).size()

However, it doesn't work. I got this issue, and I can't figure why.

ValueError: Grouper and axis must be same length

CodePudding user response:

Try with

 col_y = "Rating M"
 base_plot2 = base_plot.groupby(["pred", col_y]).size()

Or

 base_plot.groupby(["pred","Rating M"]).size()
  • Related