Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

localizing rows from a dataframe

I working with a dataframe which has 20 columns but I’m only going to use three of them in my task, which are named "Price","Retail" and "Profit" and are like this:

cols = ['Price', 'Retail','Profit']
df3.loc[:,cols]
    Price   Retail  Profit
0   861.5   1315.233051 453.733051
1   901.5   1315.233051 413.733051
2   911.0   1315.233051 404.233051
3   901.5   1315.233051 413.733051
4   901.5   1315.233051 413.733051
... ... ... ...
2678    14574.0 21546.730769    6972.730769
2679    35708.5 52026.764706    16318.264706
2680    35708.5 52026.764706    16318.264706
2681    163276.5    250882.500000   87606.000000
2682    7369.5  11785.729730    4416.229730
2683 rows × 3 columns

My goal is to find the lines where the prices are lower than 5000 and sort by the biggest values of profit. How can I make it?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You for example use query and sort_values

df3.query("Price < 5000").sort_values("Profit", ascending=False)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading