Is there a way to get Python to print out specific values in a data set that meet a certain requirement

214 Views Asked by At

I want Python to only print the values that are larger than a certain value out of a dataset. q1 is a variable representing the 25th percentile, q3 is a variable representing the 75th percentile, iqr represents the function q3-q1.

#Finding Outliers
  lower_fence = q1-(1.5*iqr)
    print('Lower Fence:', lower_fence)
  greater_fence = q3+(1.5*iqr)
    print('Greater Fence:', greater_fence)
#I am trying to get Python to only print values that are larger than the greater_fence out of the dataset
  if df['Hours'] >= greater_fence:
    print(df['Hours'] >= greater_fence)

What ends up happening is the dataset of 50+ gets printed as true/false the whole way. I am trying to get it to only print out what values meet the criteria and not everything else. It also would help for it to print out what those values are other than the fact that they exist.

1

There are 1 best solutions below

0
On

Try:

#Finding Outliers
    lower_fence = q1-(1.5*iqr)
    print('Lower Fence:', lower_fence)
    greater_fence = q3+(1.5*iqr)
    print('Greater Fence:', greater_fence)

    df_out = df[df['Hours']>= greater_fence]
    print(df_out)