0

I want to assign values to my variable, so that it should contain all values greater than specific value. I am using np.range but here also we need to pass argument as np.range(start_range, end_range, Difference between two values) .I want my variable to contain all values greater than (start_range)

I have dataframe which contains a column Score range 0-1. Say i have created a function as below :

def get_data(Data, score):
    ......
    ......

Now when I call this function , I want all the records from my Dataframe that has score more than 0.8.

Is there any other way to assign the value in range?

5
  • That sounds like you may not quite understand how variables work. Why do you think you need your variable to contain all values greater than a specific number? What problem are you trying to solve by doing this? Commented Feb 13, 2019 at 9:26
  • Python doesn't support infinitely large data structures...maybe try Haskell? Commented Feb 13, 2019 at 9:27
  • 1
    There is also the issue that numbers go up to positive infinity... so you are probably looking for something else, not what you described in the question. Maybe just an if x > start_range: Commented Feb 13, 2019 at 9:28
  • @JoshFriedlander It does. It's called generator. Commented Feb 13, 2019 at 9:45
  • @user2357112- I have a data frame , that contains a column of score range 0-1. Now I am writing a function where I am passing the score variable. But while calling the function I want to pass the value of the score as it should contain only values >=0.8. Commented Feb 13, 2019 at 9:48

1 Answer 1

2

I think you want to return all values from your dataframe greater than a threshold (0.8). range is not the tool for this.

def get_data(df, score, column):
    """Return rows of Dataframe where 'column' has value greater than 'score'."""
    new_df = df.loc[df[column] > score]
    return new_df

>>> get_data(df, 0.8, 'Score')
Sign up to request clarification or add additional context in comments.

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.