import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
f = pd.read_excel("Modified_Spend_Data.xlsx", skiprows = 6)
f = f.astype({'Supplier Parent Code': str,'Supplier Child Code' : str,'Month':str,'Year':str,'Spend':int})
f['Parent_Child'] = f[['Supplier Parent Code', 'Supplier Child Code']].apply(lambda x: '_'.join(x), axis=1)
f.head()
m = f.groupby(['Parent_Child','Month']).agg({'Spend': 'sum'}).reset_index()
m.head(20)
vendor = 'L-1386720_C-S238' ##### change vendor name here
k = m.loc[m['Parent_Child'] == vendor]
k.plot(x = 'Month',y ='Spend',figsize = (12,8),title = 'Result for vendor ' + vendor)
plt.xticks(np.arange(len(k)), k['Month'], rotation=90)
plt.show()
y = f.groupby(['Parent_Child','Year']).agg({'Spend': 'sum'}).reset_index()
y
ven = 'L-1386720_10004661' ##### change vendor name here
j = y.loc[y['Parent_Child'] == ven]
j.plot(x = 'Year',y ='Spend',kind = 'bar',figsize = (12,8),title = 'Result for vendor ' + ven)
plt.xticks(np.arange(len(j)), j['Year'], rotation=90)
plt.show()
v = f.groupby(['Parent_Child','Year']).agg({'Spend': 'sum'})
v = v.sort_values(by=['Spend'], ascending = False).reset_index()
v
year = '2016' ##### change year here
i = v.loc[v['Year'] == year]
i = i.head(15) #### change 10 to 25 here
i.plot(x = 'Parent_Child',y ='Spend',kind = 'bar',figsize = (10,8),title = 'Spend on top 15 Vendors for year ' + year)
plt.xticks(np.arange(len(i)), i['Parent_Child'], rotation=90)
plt.xlabel("Supplier in Parent_Child format")
plt.ylabel("Spend in Dollars ")
plt.tight_layout()
plt.savefig('Spend on top 15 Vendors for year ' + year+'.png')
plt.show()