#%%
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#%%
plt.rcParams["font.sans-serif"] = "SimHei"
plt.rcParams["axes.unicode_minus"] = False
#%%
df_data = pd.read_csv("./data/uniqlo.csv")
#%%
# df_data.describe()
# df_data.info()
# df_data.shape
df_data.head()
#%%
# 1、销售情况随着时间的变化
print(df_data.shape)
df_data["wkd_ind"].unique()
reven = df_data.groupby("wkd_ind")["revenue"].mean()
reven
plt.figure(figsize=(6,4),dpi=150)
plt.bar(reven.index,reven.values)
plt.show()
#%%
df_data.groupby("wkd_ind").revenue.describe()
#%%
# 2、不同产品的销量
df_data["product"].unique()
#%%
types = df_data.groupby("product").revenue.describe()
plt.figure(figsize=(6,5),dpi=150)
plt.bar(types.index, types["mean"])
plt.show()
#%%
df_data.head()
#%%
# pip install seaborn
import seaborn as sns
plt.figure(figsize=(6,4),dpi=150)
sns.barplot(x="product",y="revenue",data=df_data)
plt.show()
#%%
types = df_data.groupby("product").revenue.mean().sort_values(ascending=False)
plt.figure(figsize=(6,5),dpi=150)
plt.bar(types.index,types.values,color=["red","orange","green","yellow"])
plt.show()
#%%
plt.figure(figsize=(6,4),dpi=150)
sns.barplot(
x="product",
y="revenue",
data=df_data,
order=df_data.groupby("product").revenue.mean().sort_values(ascending=False).index
)
#%%
# 每个城市的人喜欢的购物方式
df_data.head()
#%%
df_data["channel"].unique()
#%%
df_data.groupby(["city","channel"]).revenue.mean()
#%%
plt.figure(figsize=(6,4),dpi=150)
sns.barplot(
x="city",
y="revenue",
data=df_data,
hue="channel",
estimator=sum,
# order=df_data.groupby("city").revenue.sum().sort_values(ascending=False).index
)
plt.show()
#%%
df_data.head()
#%%
# 不同年龄段的购物方式
plt.figure(figsize=(6,4),dpi=150)
sns.barplot(
x="age_group",
y="revenue",
hue="channel",
data=df_data,
order=df_data.groupby("age_group").revenue.sum().sort_values(ascending=False).index
)
plt.show()
#%%
df_data.head()
#%%
df_data["price"] = df_data["revenue"] / df_data["quant"]
df_data["margin"] = (df_data["revenue"] / df_data["quant"]) - df_data["unit_cost"]
#%%
df_data.head()
#%%
df_data_new = pd.DataFrame({
"城市":df_data["city"],
"品牌":df_data["product"],
"利润":df_data["margin"],
"成本":df_data["unit_cost"],
"单价":df_data["price"]
})
df_data_new
#%%
datas = df_data_new.groupby("城市")["利润","成本","单价"].mean()
datas
#%%
plt.figure(figsize=(7,5),dpi=150)
width = 0.2
x = np.arange(len(datas.index))
plt.bar(x,datas["利润"],width=width,label="利润",color="red")
plt.bar(x+width,datas["成本"],width=width,label="成本",color="green")
plt.bar(x+width*2,datas["单价"],width=width,label="单价",color="orange")
plt.xticks(x+width,labels=datas.index)
plt.legend()
plt.show()
#%%
#%%
#%%
#%%
MatPlotlib基本
最新推荐文章于 2025-01-27 11:25:02 发布
1108

被折叠的 条评论
为什么被折叠?



