店铺数量城市分布图

店铺数量城市分布图

数据来源:https://www.kaggle.com/starbucks/store-locations/data
案例题目:1、使用matplotlib呈现出店铺总数排名前10的国家;2、使用matplotlib呈现出中国每个城市的店铺数量

使用matplotlib呈现出店铺总数排名前10的国家

# coding=utf-8
import pandas as pd
from matplotlib import pyplot as plt

file_path = "./data/starbucks_store_worldwide.csv"

df = pd.read_csv(file_path)

data1 = df.groupby(by="Country").count()["Brand"].sort_values(ascending=False)[:10]

_x = data1.index
_y = data1.values

#画图
plt.figure(figsize=(20,8),dpi=80)

plt.bar(range(len(_x)),_y)

plt.xticks(range(len(_x)),_x)

plt.show()

店铺数量城市分布图_第1张图片

使用matplotlib呈现出中国每个城市的店铺数量

# coding=utf-8
import pandas as pd
from matplotlib import pyplot as plt
from matplotlib import font_manager

file_path = "./data/starbucks_store_worldwide.csv"

df = pd.read_csv(file_path)
df = df[df["Country"]=="CN"]

data1 = df.groupby(by="City").count()["Brand"].sort_values(ascending=False)[:25]

_x = data1.index
_y = data1.values

#画图
plt.figure(figsize=(20,12),dpi=80)

plt.barh(range(len(_x)),_y,height=0.3,color="orange")

plt.yticks(range(len(_x)),_x,fontproperties=my_font)

plt.show()

店铺数量城市分布图_第2张图片

你可能感兴趣的:(Python数据分析,人工智能,matplotlib)