Another Strategy for assigning 1/0 for both cheap and reasonable app with losing data while assigning , else was getting None for one of the type

Screen Link:

Another Approach which passed test case of dataquest platform

My Code:

cheap = affordable_apps["Price"] < 5
reasonable = affordable_apps["Price"] >= 5

cheap_mean=affordable_apps[cheap]["Price"].mean()
reasonable_mean= affordable_apps[reasonable]["Price"].mean()

def price_criterion(element,x):
    if element < x:
        return 1.0
    else :
        return 0.0
    
    


s1 =  affordable_apps[cheap]["Price"].apply(price_criterion,args=(cheap_mean,))


s2 = affordable_apps[reasonable]["Price"].apply(price_criterion,args=(reasonable_mean,))



s3=s1.append(s2)
s3=s3.sort_index()
affordable_apps[reasonable].plot(kind="scatter", x="Price", y="Rating")

print(affordable_apps[reasonable].corr().loc["Rating", "Price"])

affordable_apps["price_criterion"] = s3

What I expected to happen:

What actually happened:

Replace this line with the output/error

Did with another way using series.append method.

Facing problem as directly assigning was giving None value as I was not using .loc for proper filtering and assigning, so I found an alternative way to tackle that problem.

Though I liked answer of Dataquest , it did not clicked me first using .loc to specify specific rows to assign .