【数据分析】Starbucks Locations Worldwide

数据来源:https://www.kaggle.com/starbucks/store-locations/data

1.中国星巴克数最多的15个城市

转为ansi避免出现乱码

import pandas as pd
from matplotlib import pyplot as plt

file_path = "./directory.csv"

df = pd.read_csv(file_path, encoding='ansi')

china_data = df[df["Country"] == "CN"]

grouped = china_data.groupby(by="City").count()['Brand']
# 统计店铺数最多的15个城市
city_data = grouped.sort_values(ascending=False)[:15]

plt.rcParams['font.sans-serif'] = ['SimHei']

_x = city_data.index
_y = city_data.values

plt.figure(figsize=(15, 8))
rects = plt.bar(range(len(_x)), _y)
plt.xticks(range(len(_x)), _x)
plt.xlabel('城市')
plt.ylabel('店铺数量')
for rect in rects:
    height = rect.get_height()
    plt.text(rect.get_x() + rect.get_width() / 2, height + 2, str(height), ha='center')
plt.title('中国星巴克店铺最多的15个城市')
plt.show()

在这里插入图片描述
统计精确性会因数据有些偏差
在这里插入图片描述
如图会被算为两个市

2.各国星巴克店铺数对比

import pandas as pd
from matplotlib import pyplot as plt

file_path = "./directory.csv"

df = pd.read_csv(file_path, encoding='ansi')

grouped = df.groupby(by="Country").count()['Brand']

plt.rcParams['font.sans-serif'] = ['SimHei']

_x = grouped.index
_y = grouped.values

plt.figure(figsize=(20, 8))
rects = plt.bar(range(len(_x)), _y)
plt.xticks(range(len(_x)), _x)
plt.xlabel('国家')
plt.ylabel('店铺数量')
for rect in rects:
    height = rect.get_height()
    plt.text(rect.get_x() + rect.get_width() / 2, height + 2, str(height), ha='center')
plt.title('各国星巴克店铺数对比')
plt.show()

在这里插入图片描述
US一骑绝尘,第二的CN也没有达到零头

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

叶柖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值