I am doing an online course that is currently covering pandas and dataframes. The following code was the solution to an exercise about how to display all cars with prices between 10.000 and 50.000 in a dataframe:
# cars is a dataframe
cost = cars['price']
between = np.logical_and(cost > 10000, cost < 50000)
medium = cars[between]
print(medium)
I was wondering how I could write the first three lines of code into one. And tried something like the following but that did not work.
medium = cars[cars["price"] < 10000 and cars["price"] > 50000]]