High to low prices by region
Now you know how to sort a DataFrame, the estate agents have asked you to create a bar plot visualizing the average property price by region from largest to smallest.
regions has been created by grouping melb by region and calculating the average price, and preloaded for you:
regions = melb.groupby("region", as_index=False)["price"].mean()
Este exercício faz parte do curso
Interactive Data Visualization with Bokeh
Instruções do exercício
- Sort
regionsby price in descending order. - Create the figure, setting
x_rangeequal to the"region"column ofregionsand labeling the x- and y-axes as"Region"and"Sales", respectively. - Add bar glyphs from
regions, showing thepriceon the y-axis against eachregionon the x-axis, and setting the width to0.9 - Update the y-axis format to display in millions of dollars with 1 decimal place.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Sort df by price in descending order
regions = regions.____("____", ascending=____)
# Create figure
fig = figure(x_range=____, x_axis_label=____, y_axis_label=____)
# Add bar glyphs
fig.vbar(x=____, top=____, width=____)
# Format the y-axis to numeric format
fig.____[____].____ = ____(____="$0.0a")
output_file(filename="sorted_barplot.html")
show(fig)