'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)
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hamza |
