Calculating mean of a column using Graphlab SFrame?

User 5323 | 6/24/2016, 11:46:12 AM

I am supposed to find the average price of the houses with zipcode - 93038. So, i broke down the problem into smaller bits. This is what i tried so far.Firstly, I tried to find a way to create a filter such that i can extract only the prices of the house with zipcode - 93038. Then, i tried to print the results only the zipcode and price but it doesn't show me the columns. Also, I tried to calculate the mean of the prices with zipcode = 93038 and the result is printed as none. What could be the problem?

import graphlab
sf = graphlab.SFrame('')
filter_sf = sf[(sf['zipcode']=='98038')]
print filter_sf['zipcode','price'] 
print filter_sf['zipcode'].mean()
#The mean is printed as none. 


User 940 | 6/24/2016, 8:12:23 PM

Hi @"Surajit Das" ,

To print the results you need double square brackets, like this print filter_sf[['zipcode', 'price']]

You're also trying to get the mean of the zipcodes, which are strings, so this operation doesn't return a numeric value. What you are probably looking for is print filter_sf['price'].mean().

I hope this helps!

Cheers! -Piotr