Get startedGet started for free

Housing prices dropdown

You are working as a data analyst for a real estate investing firm. The firm has asked you to help them understand property price returns for several key Sydney suburbs over the last five years. Your work will supplement the qualitative analysis of these suburbs. They want to be able to visualize each suburb by itself but easily switch between them.

They have provided you with some data on the prices of these suburbs in 2015 and 2020.

In this exercise, you are tasked with creating a line chart of this data with a dropdown to select each suburb. Additionally, they have identified that one of the suburbs is experiencing great growth, so you want to annotate only that trace. You accept the challenge!

You have a house_prices DataFrame available, and a go.Figure() object will be set up for you.

This exercise is part of the course

Introduction to Data Visualization with Plotly in Python

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create the figure
fig = go.Figure()

# Loop through the suburbs
for suburb in ['Greenacre', 'Lakemba']:
  	# Subset the DataFrame
    df = house_prices[house_prices.Suburb == suburb]
    # Add a trace for each suburb subset
    fig.add_trace(px.line(df, x='Year', y='Median House Price').data[0])

# Annotation
ga_annotation=[{'text': 'Price boom!', 'showarrow': True, 'x': 'Year: 2018', 'y': 712678}]

# Create the buttons
dropdown_buttons = [
{'label': "Greenacre", 'method': "update", 'args': [{"visible": [____, ____]}, {'title': 'Greenacre', 'annotations': ____}]},
{'label': "Lakemba", 'method': "update", 'args': [{"visible": [____, ____]}, {'title': 'Lakemba', 'annotations': []}]},
]
Edit and Run Code