数据分析实战----星巴克门店分布的可视化分析

星巴克门店分布可视化分析

项目介绍:使用python对星巴克门店分布进行可视化分析
数据背景:数据源来自与Kaggle: Starbucks Locations Worldwide | Kaggle,囊括了截至2017/2月份全球星巴克门店的基础信息,包括品牌名称、门牌地址、所在国家、经纬度等一系列详细的信息。
任务概述:

1.导入相应的模块

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
%matplotlib inline

2.获取数据

starbucks=pd.read_csv("./data6/directory.csv")
starbucks.head()

3.数据分析和可视化

1).查看全世界一共有多少个国家和地区开设了星巴克门店,显示门店数量排名前10和后10的国家地区用柱状图绘制排名前10的分布情况

print("星巴克旗下的品牌有:",starbucks["Brand"].value_counts())
coffee=starbucks[starbucks.Brand=="Starbucks"]
print(coffee.shape)

 

df=starbucks.groupby(["Country"]).size()
print("全世界一共有多少个国家和地区开设了星巴克门店",df.size)
df1=df.sort_values()
df1.head(10)
df1.tail(10)
df1.head(10).plot(kind="bar",rot=0)
plt.title("星巴克门店排名前10的分布情况")
plt.xlabel("Store Counts")
plt.ylabel("Counties and Regions")
plt.show()

 

2).显示拥有星巴克门店数量排名前10的城市

count_starbucks_city=coffee.City.value_counts()
count_starbucks_city.head(10)

 

3).绘制星巴克门店数前10的城市分布柱状图

count_starbucks_city=coffee.City.value_counts()
city_top10=count_starbucks_city.head(10)
city_top10.plot(kind="bar",rot=30)
plt.title("星巴克门店数前10的城市分布柱状图")
plt.xlabel("City")
plt.ylabel("Store Counts")
plt.figure(1,figsize=(8,6))
plt.show()

 

4).按照星巴克门店在中国的分布情况,统计排名前10的城市

import pinyin
#选择中国的数据
df=starbucks[starbucks["Country"]=="CN"]
df1=df.copy()
#将城市名改为小写
df1["City"]=df1["City"].apply(lambda x:x.lower())
#将汉字城市名改为小写拼音,去掉“市”字的拼音
df1["City"]=df1["City"].apply(lambda x:pinyin.get(x,format="strip",delimiter="")[0:-3])
#统计每个城市的星巴克门店数量
df1=df1.groupby(["City"]).size().sort_values(ascending=False)
df1.head(10)

 

5).绘制柱状图

df1.head(10).plot(kind="bar",rot=30)
plt.title("星巴克门店数在中国城市的分布情况")
plt.xlabel("China City")
plt.ylabel("Store Counts")
plt.figure(1,figsize=(8,6))
plt.show()

 

6).用饼图显示星巴克门店的经营方式有哪几种

ownerships=starbucks["Ownership Type"].value_counts()
plt.title("星巴克门店的经营方式")
ownerships.plot(kind="pie")
plt.figure(1,figsize=(8,6))
plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Emily2548

你的打赏就是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值