ValueError: Grouper for not 1-dimensional

前端 未结 5 1842
梦如初夏
梦如初夏 2020-12-30 19:40

I\'m have the following code which creates a table and a barplot via seaborn.

#Building a dataframe grouped by the # of Engagement Types
sales_type = sales.g         


        
5条回答
  •  傲寒
    傲寒 (楼主)
    2020-12-30 19:47

    Something to add to @w-m's answer.

    If you are adding multiple columns from one dataframe to another:

    df1[['col1', 'col2']] = df2[['col1', 'col2']]
    

    it will create a multi-column index and if you try to group by anything on df1, it will give you this error.

    To solve this, get rid of the multi-index by using

    df1.columns = df1.columns.get_level_values(0)
    

提交回复
热议问题