How do logic work in SFrame in Python?

2

I'm new with python but I know R. I want to obtain certain houses with Python thanks to logical conditions that are houses with more than 2000 square meters but less than 4000 square meters. I use this website to understand how to use the logical conditions but I do not achieve a result.

Here is my request:

housesRangeSqft = test_data[(test_data('sqft_living'>=2000)) & (test_data('sqft_living'<=4000))]

But I get the following error in jupyter notebook:

TypeError                                 Traceback (most recent call last)
<ipython-input-40-7e39708087dd> in <module>()
----> 1 housesRangeSqft = test_data[(test_data('sqft_living'>=2000)) & (test_data('sqft_living'<=4000))]
TypeError: 'SFrame' object is not callable

Here is the structure of test_data :

    
asked by ThePassenger 04.04.2017 в 14:17
source

1 answer

1

As it seems you try to make a logical filter, in Python the parentheses indicate call to method or function, as an object SFrame can not be excuted you get that error. The problem is that to access the column you do something like:

test_data('sqft_living'>=2000)

When it should be like this:

test_data['sqft_living']>=2000

See how brackets are used, not parentheses to get the column (as if it were a simple Python dictionary).

The code should look like this:

housesRangeSqft = test_data[(test_data['sqft_living']>=2000) & (test_data['sqft_living']<=4000)]
    
answered by 04.04.2017 / 14:45
source