Zillow ranked the California city at the top of its Trick-or-Treat Index for the third year in a row, based on its home values, population density, walkability and crime data.

Zillow assumed higher home values would translate into wealthier owners buying the good candy — we're talking king-sized chocolate bars — to give out on Halloween.

"San Francisco has some of the highest home values and incomes in the country," said Amy Bohutinsky, chief marketing officer for Zillow. "Plus, it's a dense urban area. You can hit lots of single family homes side by side. It's the perfect storm of all our factors."

Although San Francisco consistently ranks highly on Zillow's Trick-or-Treat Index, the neighborhoods within the city often jockey for first place. This year, Noe Valley — a residential, family-filled neighborhood in central San Francisco — was named the best neighborhood for Halloween, followed by Sea Cliff, Cow Hollow, Presidio Heights, and Glen Park.

Bohutinsky, who used to live in the #4-ranked neighborhood, said Noe Valley was the neighborhood where people moved when they wanted to have kids. It also boasts a ton of sidewalks, a big plus for young trick-or-treaters. But it was really a shift in crime data and home values that put Noe Valley at the top.

Homes in the ritzy neighborhood were worth an average of $1.43 million in August 2013, a 17.7% increase over the previous year, according to Zillow. It also scored an 86 out of 100 on WalkScore.com, which earned Noe Valley a "very walkable" rating.

"The top ten cities stay fairly consistent," Bohutinsky said, "but it's interesting to see how those cities move up or down. House value shifts in the last year have been especially interesting as primary data."