You can see the data cleansing process here.
import pandas as pd
import datetime
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
%matplotlib inline
data = pd.read_pickle("retail_price_data.pkl")
def plot_price(series_list, title_str, xlabel_str, ylabel_str, leg_loc = "best", leg_out = False, disable_leg = False):
fig, ax = plt.subplots()
fig.set_size_inches(12, 6)
data_index = series_list[0].index
for s in series_list:
ax.plot(data_index.to_pydatetime(), s, label = s.name, lw = 2)
plt.grid(True)
years = mdates.YearLocator()
yearsFmt = mdates.DateFormatter('%Y')
ax.xaxis.set_major_locator(years)
ax.xaxis.set_major_formatter(yearsFmt)
datemin = datetime.date(data_index.date.min().year, 1, 1)
datemax = datetime.date(data_index.date.max().year + 1, 1, 1)
ax.set_xlim(datemin, datemax)
legend_font = {'family': 'ETBembo', 'size' : 17, 'style' : 'italic'}
if disable_leg:
pass
elif leg_out:
L = ax.legend(frameon = True, loc = 'center left', bbox_to_anchor=(1, 0.5))
plt.setp(L.texts, **legend_font)
else:
L = ax.legend(frameon = True, loc = leg_loc)
L.get_frame().set_edgecolor('w')
plt.setp(L.texts, **legend_font)
title_font = {'family': 'ETBembo', 'size' : 20, 'style' : 'italic'}
plt.title(title_str, y=1.02, **title_font)
plt.yticks(family = "mononoki", size = 13)
plt.xticks(family = "mononoki", size = 13, rotation = 45)
label_font = {'family': 'ETBembo', 'size' : 16, 'style' : 'normal'}
plt.xlabel(xlabel_str, **label_font)
plt.ylabel(ylabel_str, **label_font)
plt.style.use("custom")
plt.show()
plot_price([data["Gram"], data["Tur"], data["Urad"], data["Moong"], data["Masoor"]],
"Retail Prices of Dals", "Year", "Price in Rs./Kg.")
plot_price([data["Potato"], data["Tomato"], data["Onion"]],
"Retail Prices of Vegetables", "Year", "Price in Rs./Kg.")
plot_price([data["Rice"], data["Wheat"], data["Atta (Wheat)"]], "Retail Prices of Grains", "Year", "Price in Rs./Kg.")
plot_price([data["Groundnut Oil"],data["Mustard Oil"], data["Palm Oil"], data["Sunflower Oil"], data["Soya Oil"]],
"Retail Prices of Oils", "Year", "Price in Rs./Kg.", leg_out = True)
plot_price([data["Sugar"], data["Gur"]], "Retail Prices of Sugar and Gur", "Year", "Price in Rs./Kg.")
plot_price([data["Vanaspati"]], "Retail Prices of Vanaspati", "Year", "Price in Rs./Kg.", disable_leg = True)
plot_price([data["Salt (Iodised)"]], "Retail Prices of Iodised Salt", "Year", "Price in Rs./Kg.", disable_leg = True)
plot_price([data["Tea (Loose)"]], "Retail Prices of Loose Tea", "Year", "Price in Rs./Kg.", disable_leg = True)
plot_price([data["Milk"]], "Retail Prices of Milk", "Year", "Price in Rs./Litre", disable_leg = True)