# RESOLUCIÓN ANALÍTICA
df2 = my_df.groupby('article_name').sum()
por_cant = df2.sort_values('quantity', ascending=False)
print(por_cant['quantity'].head(1))
print(df2.head())
# RESOLUCIÓN GRÁFICA
sns.barplot(x=df2.index,y=df2['quantity'],data=df2, saturation=.8, order=df2.sort_values('quantity', ascending=False).index).set_title("Artículo más vendido")
sns.set( rc = {'figure.figsize' :(20, 10), 'axes.labelsize': 12 },style='whitegrid',font_scale =1.9)
plt.xticks(rotation=90)
plt.xlabel('Artículo')
plt.ylabel('Cantidad')
plt.show()
# RESOLUCIÓN ANALÍTICA
df3=(my_df.groupby('article_name').sum()).sort_values('total_amount', ascending=False).head(5)
print(df3['total_amount'])
# RESOLUCIÓN GRÁFICA
fig = plt.figure()
fig.set_figheight(8)
colors = ['#ff9999','#66b3ff','#99ff99','#ffcc99','#ff9950']
textprops = {"fontsize":15}
plt.pie(x=df3['total_amount'],labels=df3.index,textprops =textprops, colors=colors, autopct='%.1f%%',pctdistance=0.8, labeldistance=1)
plt.legend(fontsize=10, loc='upper center', bbox_to_anchor=(0.5, -0.04), ncol=2)
plt.title('5 artículos con más ingresos',fontweight='bold')
centre_circle = plt.Circle((0, 0), 0.70, fc='white')
fig = plt.gcf()
fig.gca().add_artist(centre_circle)
plt.show()
# RESOLUCIÓN ANALÍTICA
df4 =(my_df.groupby('seller_name').sum()).sort_values('total_amount', ascending=False)
print('Respuesta:', df4.head(1) )
print()
print(df4[['quantity']+['total_amount']])
# RESOLUCIÓN GRÁFICA2
sns.barplot(x=df4.index,y=df4['total_amount'],data=df4, saturation=.8, order=df4.sort_values('total_amount', ascending=False).index).set_title("Mejor Vendedor")
sns.set( rc = {'figure.figsize' :(20, 10), 'axes.labelsize': 12 },style='whitegrid',font_scale =1.9)
plt.xticks(rotation=90)
plt.xlabel('Vendedor')
plt.ylabel('Monto Vendido')
plt.show()
cross3.plot(kind = 'bar',
stacked = True,
title = 'Barras Apiladas País y Producto',
mark_right = True,
cmap='hsv',
fontsize=13,
figsize= (10,7),
width=0.9,
style='whitegrid').set_facecolor('w')
plt.legend(bbox_to_anchor=(1.05, 1.0), loc='upper left')
plt.rc('legend', fontsize=10)
# RESOLUCIÓN ANALÍTICA
df5 = (my_df.groupby('week').sum()).sort_values('total_amount',ascending=False)
print(df5)
# RESOLUCIÓN GRÁFICA 2
sns.barplot(x=df5.index,y=df5['total_amount'],data=df5, palette="Set2",saturation=.8, order=df5.sort_values('total_amount', ascending=False).index).set_title("Ventas Semanales")
sns.set( rc = {'figure.figsize' :(20, 10), 'axes.labelsize': 12 },style='whitegrid',font_scale =1.9)
plt.xticks(rotation=0)
plt.xlabel('Semana')
plt.ylabel('Monto Vendido')
plt.show()
# RESOLUCIÓN ANALÍTICA
df6 = (my_df.groupby('country_name').sum()).sort_values('total_amount',ascending=False)
print('Respuesta:', df6.head(1))
print()
print(df6[['quantity']+['total_amount']].head())
#RESOLUCIÓN GRÁFICA
sns.barplot(x=df6.index,y=df6['total_amount'],data=df6, saturation=.8, order=df6.sort_values('total_amount', ascending=False).index).set_title("Ventas por País")
sns.set( rc = {'figure.figsize' :(12, 10), 'axes.labelsize': 12 },style='whitegrid',font_scale =1)
plt.xticks(rotation=90)
plt.xlabel('País')
plt.ylabel('Monto Vendido')
plt.show()
# RESOLUCIÓN
# Para encontrar relación hacemos un pairplot
# Las variables que pudieran relacionarse son:week, quantity y total_amount
sns.pairplot(my_df)
# En el gráfico se puede ver que hay una relación entre quantity y total_amount
# Para encontrar mejor relación, distinguimos por article_name
# Esto es lógico porque total_amount se obtuvo el cálculo de quantity*unit_price
# La relación entre quantity y total_amount se da en diferente proporción para cada artículo
sns.pairplot(my_df, hue='article_name')
plt.rc('legend', fontsize=12)
plt.show()
# RESOLUCIÓN ANALÍTICA
#Creamos una tabla cruzada para ver los productos vendidos en cada país
cross2=pd.crosstab(my_df.country_name, my_df.article_name, my_df.total_amount, aggfunc=np.sum)
print(cross2.head())
# RESOLUCIÓN GRÁFICA
cross2.plot(kind = 'bar',
stacked = True,
title = 'Barras Apiladas País y Producto',
mark_right = True,
cmap='hsv',
fontsize=10,
width=0.9,
figsize= (11,6),
style='whitegrid').set_facecolor('w')
sns.set( rc = {'figure.figsize' :(10, 10), 'axes.labelsize': 12 },style='whitegrid',font_scale =1)
plt.legend(bbox_to_anchor=(1.05, 1.0), loc='upper left')
plt.rc('legend', fontsize=12)
8. Análisis del Total_amount
sns.distplot(my_df.total_amount,kde=False, bins=10)
plt.show()
9. Full_Pc
sns.boxplot(x='article_name', y='quantity', data=my_df)
plt.xticks(rotation=90)
plt.show()
sns.boxplot(x='article_name', y='total_amount', data=my_df)
plt.xticks(rotation=90)
plt.show()