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

Pandas Check two data frame columns and access third value

I am very beginner to pandas though I solved same case with comparison
here is data frame I was working

s= [
     {
         'from':0,
         'to':400000000,
         'value':0.01
     },
     {
        'from':400000001,
        'to':500000000,
        'value':0.015
    },
    {
        'from':500000001,
        'to':1000000000,
        'value':0.03
    },
    {
        'from':1000000001,
        'to':10000000000,
        'value':0.04
    }
 ]

I want to compare two fields i.e from and to and get third value that is value
suppose the car price range is between 0 and 400000000 then I may get commission of 1% i.e 0.01 bla bla
Any way of doing this in pandas way.
Here is little thing I worked on but I got empty data series

df = pd.DataFrame(s)

df = df[(df['from']<=0) &(400000000<df['to'])]['value']
print(df)

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 just need to apply those conditions correctly. Since there is no value that satisfies both conditions. You can do:

df[df['from'].le(0) & df['to'].le(400000000)]['value']

And it will result in:

0    0.01
Name: value, dtype: float64
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