0

I have a dataset, df, where I would like to show only the max distinct values.

DATA

type    power
a_b     5
a_c     6
a_c     4
a_c     4
a_b     6
a_b     9

DESIRED

type    power
a_b     9
a_c     6

DOING

df1 = df.unique
df2 = max(df1)

Any suggestion is appreciated

Lynn
  • 4,292
  • 5
  • 21
  • 44
  • 1
    Isn't the max of a_b 9 in your example? And what outcome are you getting from your current attempt? – ScienceSnake Feb 05 '21 at 18:45
  • Yes I updated. Let me update the result I am getting – Lynn Feb 05 '21 at 18:47
  • Please supply the expected [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) (MRE). Show where the intermediate results differ from what you expected. We should be able to copy and paste a contiguous block of your code, execute that file, and reproduce your problem along with tracing output for the problem points. This lets us test our suggestions against your test data and desired output. – Prune Feb 05 '21 at 18:52
  • Please [include a minimal data frame](https://stackoverflow.com/questions/52413246/how-to-provide-a-reproducible-copy-of-your-dataframe-with-to-clipboard) as part of your MRE. – Prune Feb 05 '21 at 18:52

1 Answers1

1

This is groupby:

df.groupby('type', as_index=False)['power'].max()
Quang Hoang
  • 146,074
  • 10
  • 56
  • 74