Keep columns after a groupby in an empty dataframe

前端 未结 1 1391
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-19 03:36

The dataframe is an empty df after query.when groupby,raise runtime waring,then get another empty dataframe with no columns.How to keep the columns?

df = pd.         


        
1条回答
  •  说谎
    说谎 (楼主)
    2021-01-19 03:57

    You need as_index=False and group_keys=False:

    df = df.groupby(["PlatformCategory","Platform","ResClassName"], as_index=False).count()
    df
    
    Empty DataFrame
    Columns: [PlatformCategory, Platform, ResClassName, Amount]
    Index: []
    

    No need to reset your index afterwards.

    0 讨论(0)
提交回复
热议问题