image_output_1.png
from subprocess import check_output

import matplotlib.pyplot as plt

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
import seaborn as sns
import math
from IPython.display import HTML
from subprocess import check_output

State_time_series = pd.read_csv('../input/State_time_series.csv', parse_dates=True)
State_time_series.Date = pd.to_datetime(State_time_series.Date)

states = set(State_time_series[~State_time_series['ZHVI_AllHomes'].isnull() & ~State_time_series['MedianSoldPrice_AllHomes'].isnull()]['RegionName'].values)
State_time_series_year = State_time_series[State_time_series['RegionName'].isin(states)].copy()
highest_cost_states = State_time_series_year[['RegionName', 'ZHVI_AllHomes']].groupby('RegionName').max().sort_values(by=['ZHVI_AllHomes'], ascending=False)[:5].index.values.tolist()
State_time_series_year = State_time_series_year[State_time_series_year.RegionName.isin(highest_cost_states)]
State_time_series_year.year = State_time_series_year.Date.dt.year

States_year_SalePrices = State_time_series_year.groupby([State_time_series_year.year, State_time_series_year.RegionName])['MedianSoldPrice_AllHomes'].mean().dropna().reset_index(name='SoldPrice')
States_year_SalePrices.pivot(index='Date', columns='RegionName', values='SoldPrice').plot(figsize=(15, 8), linewidth=3, fontsize=14)
plt.legend(fontsize=14)
plt.ylabel('MedianSoldPrice_AllHomes')
plt.xlabel('Year')
plt.title('Top 5 US states and their Median Sold Prices over the years 1996 to 2016')
plt.gca().get_xaxis().get_major_formatter().set_useOffset(False)