The world’s leading publication for data science, AI, and ML professionals.

Demographic Analysis of the Des Moines Farmers Market with Foot Traffic Data

Learn how to analyze foot traffic to non-POI events, such as farmers markets, demonstrations, fairs, and more

Photo by Dane Deaner on Unsplash
Photo by Dane Deaner on Unsplash

Some events, like the legendary Des Moines Farmers Market, aren’t confined to specific points of interest, the level at which foot traffic data is traditionally available. A number of entities may be interested in analyzing the Farmers Market’s foot traffic, such as local hotels/restaurants, the City of Des Moines, potential vendors, and academic researchers.

Here are just a few of the challenges posed by analyzing foot traffic at the Des Moines Farmers Market:

  • It corresponds to a large area that contains more traditional POIs like restaurants, banks, etc
  • The Farmers Market only occupies the area on Saturdays during certain months
  • Vendor locations within the Farmers Market move from week to week

Have no fear, Neighborhood Patterns is here!

With Neighborhood Patterns, we can answer questions about the number of visitors, where they come from, how long they stayed, and more. Better yet, this dataset and others are free for academics. If you want to extend this analysis, or research your own problems using foot traffic data, visit the SafeGraph Community.

To run the code and play with the data yourself, check out the accompanying Colab notebook!

Setup

Before every exciting analysis is a somewhat boring (yet important!) setup section. For simplicity’s sake, we will skip some of the boring stuff (imports, installations, reading in the data, etc). Feel free to check those code snippets out in the Colab notebook!

Let’s take a look at our data! The first DataFrame is the SafeGraph Neighborhood Patterns for downtown Des Moines. Specifically, we’ve filtered to the Census Block Group that contains the Des Moines Farmers Market. Census Block Groups (CBGs) are the geographic areas that Neighborhood Patterns data are aggregated at – conveniently, Census data are also aggregated at the CBG level.

A subset of the columns from SafeGraph Neighborhood Patterns.
A subset of the columns from SafeGraph Neighborhood Patterns.

Neighborhood Patterns has a bunch of useful columns. We’ll just use weekend_device_home_areas in this article, but you can edit the code to use other columns as you see fit! The complete column list is available in the documentation.

The weekend_home_device_areas column is important, so let’s break it down a bit. Each entry is a JSON object (or Python dictionary), where the key is a CBG and the value is the number of visitors seen who live in that CBG. Additionally, these visits all occurred during the weekend. The row specifies the date range that the visits occurred in. In summary, this column tells us the home CBGs of weekend visitors to downtown Des Moines.

Our next dataset is the Census data. This data allows us to ask questions about visitor Demographics. What is the average age of Farmers Market visitors? What does the income distribution look like? Census data has a ton of columns; for simplicity, we will only use median age and median income. Again, feel free to change the code if you’d like to investigate other columns – you have access to all the code/data needed to recreate this analysis in literally seconds!

A subset of columns from the Census data.
A subset of columns from the Census data.

Notice the first column: census_block_group. This column enables us to join the demographic data with Neighborhood Patterns visit data. In order to do that, we’ll need to extract the CBG-level visitor counts from weekend_device_home_areas first. We vertically explode the column, so that each key-value pair in each row is given its own row. We’ll also reformat the date column so it’s easier to read.

A subset of Neighborhood Patterns after vertically exploding the weekend_device_home_areas column
A subset of Neighborhood Patterns after vertically exploding the weekend_device_home_areas column

Now we can join our two datasets to see the median age and median income for each CBG that visited downtown Des Moines on the weekend.

Our merged dataset.
Our merged dataset.

Analysis

Our analysis will be kept fairly simple. We will look at the median age and median income distributions for each month in 2018 and 2019 (note: the Des Moines Farmers Market only runs from May through October). To do this, we create histograms, where each row is weighted by the number of visitors (weekend_device_home_areas_value).

Distribution of median incomes for weekend visitors to downtown Des Moines.
Distribution of median incomes for weekend visitors to downtown Des Moines.

The means range from $75,347 to $79,948. Interestingly, the mean income drops off in September and October.

Now let’s take a look at the same visualizations for median age.

Distribution of median ages for weekend visitors to downtown Des Moines.
Distribution of median ages for weekend visitors to downtown Des Moines.

The mean ranges from 36.6 to 37.8 years old. Again, we see a dip in September and October, relative to June and July!

One might hypothesize that the income and age dip we see in September and October is caused by university students returning to school. We will test this hypothesis in Part Two: Mapping Visitors to the Des Moines Farmers Market!

Conclusion

In this article, we went through how to analyze demographics for visitors to the Des Moines Farmers Market, an event that is confined to an area rather than a traditional point of interest. This was all made possible with SafeGraph’s Neighborhood Patterns (free for academics) and US Census data (free for everyone).

Our analysis suggests a slight decrease in both income and age in September and October. We hypothesized that this is caused by college students returning to school in Des Moines. Although we won’t statistically test this hypothesis, visualizing on a map may give us some insight! Keep an eye out for Part Two, coming soon!


Questions?

I invite you to ask them in the #safegraphdata channel of the SafeGraph Community, a free Slack community for data enthusiasts. Receive support, share your work, or connect with others in the GIS community. Through the Safegraph Community, academics have free access to data on over 7 million businesses in the USA, UK, and Canada.


Related Articles