ComeçarComece de graça

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

Ver curso

Instruções do exercício

  • Sort regions by price in descending order.
  • Create the figure, setting x_range equal to the "region" column of regions and labeling the x- and y-axes as "Region" and "Sales", respectively.
  • Add bar glyphs from regions, showing the price on the y-axis against each region on the x-axis, and setting the width to 0.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)
Editar e executar o código