Search code examples
pandasgroup-byminimum

Finding the minimum value based on another column in pandas


dataframe df

I have to find the channel type that has the minimum value of sales among all 3 channels (Hotel,Cafe or restaurant) of dataframe df(snapshot attached).So output would be the channel with minimum sales. The code i am writing is below:

df1=df.groupby(['Channel']).sum()

df1=df1.sum(axis=1)

print(df1[['Channel']].idxmin())

But it seems to be some 'index error'. Do i need to set Channel as index and find? Or is there any other approach?


Solution

  • Change your last line

    print(df1.idxmin())