Análisis de los 25 retailers más grandes de Estados Unidos
# Importar librerías
from IPython.display import display
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# Importar datos aquí
df = pd.read_csv("largest_us_retailers.csv")
df.head()
Companyobject
Salesint64
0
Walmart US
658119
1
Kroger
115037
2
Costco
90048
3
Home Depot
83976
4
Walgreen Boots
78924
df.describe()
Salesfloat64
Storesfloat64
count
25
23
mean
71063.08
3466.565217
std
125405.7276
4038.708714
min
16592
231
25%
24402
1029
50%
34980
1828
75%
71687
4242
max
658119
14250
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 25 entries, 0 to 24
Data columns (total 6 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Company 25 non-null object
1 Sales 25 non-null int64
2 Stores 23 non-null float64
3 Sales/Avg. Store 23 non-null float64
4 Store Count Growth 23 non-null float64
5 Category 24 non-null object
dtypes: float64(3), int64(1), object(2)
memory usage: 1.3+ KB
I. Preguntas del negocio
sns.boxplot(df["Sales"][1:-1])
promedio = str(df["Sales"][1:-1].mean().round(2))
plt.title("Promedio:"+ promedio)
/shared-libs/python3.7/py/lib/python3.7/site-packages/seaborn/_decorators.py:43: FutureWarning: Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
FutureWarning
# sns.histplot(df[1:-1], x="Sales")
# plt.title("La mayoria de la empresas sin contar la numero uno gano entre: 18,201 y 34,340.3")
f, (ax_box, ax_hist) = plt.subplots(2, sharex=True, gridspec_kw={"height_ratios": (.15, .85)})
sns.histplot(df, x="Sales", ax=ax_hist)
sns.boxplot(df["Sales"], ax=ax_box)
txt_1 = "La mayoria de las compañias gano entre: 16,592 y 48,668.3"
plt.figtext(0.5, 1, txt_1, wrap=True, horizontalalignment='center', fontsize=12)
/shared-libs/python3.7/py/lib/python3.7/site-packages/seaborn/_decorators.py:43: FutureWarning: Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
FutureWarning
f, (ax_box, ax_hist) = plt.subplots(2, sharex=True, gridspec_kw={"height_ratios": (.15, .85)})
con = sns.histplot(df, x="Stores", ax=ax_hist)
sns.boxplot(df["Stores"], ax=ax_box)
txt_1 = "La mayoria de las compañias tiene entre: 231 y 2,233 tiendas"
plt.figtext(0.5, 1, txt_1, wrap=True, horizontalalignment='center', fontsize=12)
/shared-libs/python3.7/py/lib/python3.7/site-packages/seaborn/_decorators.py:43: FutureWarning: Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
FutureWarning
sns.scatterplot(data=df, x = 'Stores', y = "Sales")
txt = "La compañia con mas tiendas no es la numero uno en ventas \n La numero uno en ventas tiene menos de un tercio en comparacion de la que tiene mas tiendas"
plt.figtext(0.5, 1, txt, wrap=True, horizontalalignment='center', fontsize=12)
max_sales = df["Sales"].max()
min_sales = df["Sales"].min()
range_sales = max_sales - min_sales
print("Ventas maximas:", max_sales)
print("Ventas minimas:", min_sales)
print("Rango entre las venats:", range_sales)
Ventas maximas: 658119
Ventas minimas: 16592
Rango entre las venats: 641527
more_stores = df.nlargest(5, "Stores")
more_sales = df.nlargest(5, "Sales")
print("Compañias con mas tiendas físicas")
display(more_stores)
print("De las cinco compañias con mas tiendas físicas, solo dos estan entre las que mas ventas tienen")
pd.merge(more_stores,more_sales,on='Company')
Compañias con mas tiendas físicas
De las cinco compañias con mas tiendas físicas, solo dos estan entre las que mas ventas tienen
Companyobject
Sales_xint64
0
Walgreen Boots
78924
1
Walmart US
658119
print("La categoria con mas ventas es: Supercenters")
sns.barplot(data=df, x="Sales", y="Category")
La categoria con mas ventas es: Supercenters
company_supercenters = df[(df["Category"]=="Supercenters")]
sns.barplot(data=company_supercenters, x="Sales", y="Company")
plt.title("Compañias dentro de la categoria Supercenters", size=12)
sns.barplot(data=df, x = 'Sales/Avg. Store' , y="Company")
plt.title("Costco Es la compañia que genera mas ventas por tienda")
print("Amazon y Apple no cuentan con tiendas fisicas")
print("amazon esta en el lugar numero 7 en ventas")
print("Apple esta en el lugar nuero 12 en ventas")
print("Sus ventas si destacan sobrelas que tienen tiendas físicas")
df[df['Stores'].isnull()]
Amazon y Apple no cuentan con tiendas fisicas
amazon esta en el lugar numero 7 en ventas
Apple esta en el lugar nuero 12 en ventas
Sus ventas si destacan sobrelas que tienen tiendas físicas
Companyobject
Salesint64
6
Amazon
71687
11
Apple incl. Online
37664
idx_no_stores =[6, 11]
clrs = ["red" if x in idx_no_stores else "red" for x in df["Company"] ]
ax = sns.barplot(data=df, x="Sales", y="Company")
for bar in ax.patches:
if bar.get_y().round() in idx_no_stores:
bar.set_color('red')
else:
bar.set_color('grey')
sns.scatterplot(data=df, x="Sales/Avg. Store", y="Stores")
txt = "En la grafrica se puede notar que a en la matoria de las compañias a moyor tiendas tiene menores son sus ventas por tienda"
plt.figtext(0.5, 1, txt, wrap=True, horizontalalignment='center', fontsize=12)
sns.jointplot(data=df, x="Store Count Growth", y="Sales/Avg. Store")
"Sales/Avg. Store"