Intro:
Visualizing data can be a powerful way to convey complex information in a simple and engaging manner. When it comes to understanding long-term trends or patterns, such as the increase in property prices over a span of 25 years, traditional static charts or graphs may not effectively capture the dynamic nature of the data. By creating a visual representation that shows the changes in property prices over time, month by month, for the entire 25-year period, we can depict the price fluctuations as a continuous flow of information, allowing viewers to grasp the overall trend and observe how prices rise and fall over the years.
Packages:
bar_chart_race, a python package for creating bar chart races
pip install bar_chart_race
import bar_chart_race as bcr
Data Source:
The UK House Price Index (UK HPI) captures changes in the value of residential properties at regional level.
Data Pre Process:
Pre-processing would include to convert the 'Date' column to a datetime format and creates a pivot table (pvdata) with the average values of the 'Detached_Average_Price' column, using 'Date' as the index and 'Region_Name' as the columns.
df['Date'] = pd.to_datetime(df['Date'])
pvdata = df.pivot_table("Detached_Average_Price", index = "Date",columns = ["Region_Name"], aggfunc = np.average)
Next step would be to sorts the index, fills missing values, adds a 'month_year' column, sets it as the new index, resets the index to a numerical index, and finally groups the data by month and calculates the mean values
pvdata.sort_index(inplace=True, ascending=True)
pvdata = pvdata.fillna(0)
pvdata['month_year'] = pvdata.index.strftime('%Y-%m')
pvdata_month = pvdata.set_index("month_year")
pvdata_month.reset_index()
pvdata_monthgr = pvdata_month.groupby('month_year').mean()
Visualizing the data:
bcr.bar_chart_race(df = pvdata_monthgr,
filename = "growthbyregion.gif",
filter_column_colors = True,
cmap = "prism",
title = "Average House Price By Months")
Summary:
The animation can convey a sense of movement and progression, providing a more intuitive and engaging understanding of the data than a static chart or graph and allowing viewers to easily grasp the complex information and gain valuable insights from the data
Reference:
Top comments (0)