Converting a Pandas GroupBy output from Series to DataFrame

后端 未结 9 679
广开言路
广开言路 2020-11-22 09:58

I\'m starting with input data like this

df1 = pandas.DataFrame( { 
    \"Name\" : [\"Alice\", \"Bob\", \"Mallory\", \"Mallory\", \"Bob\" , \"Mallory\"] , 
           


        
9条回答
  •  一整个雨季
    2020-11-22 10:46

    Maybe I misunderstand the question but if you want to convert the groupby back to a dataframe you can use .to_frame(). I wanted to reset the index when I did this so I included that part as well.

    example code unrelated to question

    df = df['TIME'].groupby(df['Name']).min()
    df = df.to_frame()
    df = df.reset_index(level=['Name',"TIME"])
    

提交回复
热议问题