Popularity of goods sold by state
The farmer's market dataset contains columns corresponding to 28 different goods and whether or not they are sold at that market. You're curious to see if there are any interesting stories in this dataset regarding how likely you are to find a given good at a state's markets. To answer this question, you collapse the data into three columns:
state
- the name of the stategood
- the good of interestprop_selling
- the proportion of markets in that state that sell that good
To quickly determine if patterns emerge, you choose a subset of goods you find interesting and decide to make a simple text-scatter: the good on the x-axis and the proportion of a state's markets that sell that good on the y-axis.
This exercise is part of the course
Improving Your Data Visualizations in Python
Exercise instructions
Filter
goods_by_state
to the desired goods listed into_plot
.Hide the scatter plot points by setting their size to nothing.
- Note that in
sns.scatterplot()
,size
is used to map values from a column to a size scale, ands
is used to set a constant size for all points.
- Note that in
Make the text center aligned, so it sits directly on the good's x-axis location.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Subset goods to interesting ones
to_plot = ['Cheese','Maple','Fruits','Grains','Seafood','Plants','Vegetables']
goods_by_state_small = goods_by_state.____("good in "+str(to_plot))
g = sns.scatterplot('good','prop_selling', data = goods_by_state_small,
# Hide scatter points by shrinking to nothing
____ = ____)
for _,row in goods_by_state_small.iterrows():
g.annotate(row['state'], (row['good'], row['prop_selling']),
# Center annotation on axis
ha = '____',
size = 10)
plt.show()