Home > other >  How to get the minimum value of every column occurrence in a dataframe?
How to get the minimum value of every column occurrence in a dataframe?

Time:12-29

I have the following dataframe:

    layer   idx FP_part     accuracy
    conv2d  0   Mantissa    0.683099
    conv2d  1   Mantissa    0.683099
    conv2d  2   Mantissa    0.683099
    conv2d  3   Mantissa    0.683099
    conv2d  4   Mantissa    0.683099
    conv2d  0   Mantissa    0.683099
    conv2d  1   Exponent    0.683099
    conv2d  2   Exponent    0.683099
    conv2d  3   Exponent    0.683099
    conv2d  4   Exponent    0.683099
    dense_2 0   Mantissa    0.682965
    dense_2 1   Mantissa    0.682836
    dense_2 2   Mantissa    0.682940
    dense_2 3   Mantissa    0.416586
    dense_2 4   Mantissa    0.682983
    dense_2 0   Exponent    0.682965
    dense_2 1   Exponent    0.682836
    dense_2 2   Exponent    0.682940
    dense_2 3   Exponent    0.416586
    dense_2 4   Exponent    0.682983

I am trying to get the min accuracy for each layer and FP_part while keeping the index column. this is what I tried, but the idx column is remived

df_wim = df_w.groupby(['layer',"FP_part"])['accuracy'].min().reset_index()

CodePudding user response:

Try using idxmin instead of min here,

# Get the index of the row with the minimum accuracy value for each group
idx = df.groupby(['layer','FP_part'])['accuracy'].idxmin()

# Select the rows with the minimum accuracy value for each group
df_wim = df.loc[idx]

CodePudding user response:

You can try :

df_wim=df_w.groupby(by=['layer','FP_part'], sort=True,dropna=True).min([['accuracy']]).reset_index()
  • Related