0

I try to get the min and max value (as a float) of a column without the zero values.

I tried:

minValue = df[df['col1']>0.1].min()
maxValue = df['col2'].max()

type minValue --> pandas.core.series.Series
type maxValue --> float

6
  • 2
    "without the non-zero values" means you only want to look at the zeros. Which sounds wrong. Commented Jun 16, 2022 at 7:50
  • But the answer would be much simpler then: 0. ;-) Commented Jun 16, 2022 at 7:51
  • 1
    so, what failed? Can you provide a reproducible input/output example? Commented Jun 16, 2022 at 7:51
  • did you display/print minValue? I think it would help you see what the operation currently does Commented Jun 16, 2022 at 7:52
  • 2
    I think you missed to select the column where to calculate the min, try : minValue = df[df['col1']>0.1]['col1'].min() Commented Jun 16, 2022 at 7:52

2 Answers 2

1

I'd suggest:

minValue = df.col1[df.col1!=0].min()
maxValue = df.col1[df.col2!=0].max()

but you need to adapt to the columns you want to look for non-zero values and from which you want the min/max values.

Sign up to request clarification or add additional context in comments.

Comments

1

You can try

minValue = df.loc[df['col1']>0.1, 'col1'].min()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.