MatPlotlib基本

#%%

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()

#%%



#%%



#%%



#%%

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值