Python日志_20211019_1631

统计中国各城市星巴克数量方法:

(自行改动:把Hong Kong 改为香港市)

import numpy as np
import pandas as pd
from matplotlib import pyplot as plt

plt.rcParams['font.sans-serif'] = ["SimHei"]
plt.rcParams["axes.unicode_minus"] = False
pd.set_option('display.max_columns', None)

p1 = pd.read_csv("./starbucks_store_worldwide.csv")
p1 = p1[p1["Country"] == "CN"].groupby(by="City").count()["Brand"]
prepared_data = p1.sort_values(ascending=False)[:10]

data_index = np.array(prepared_data.index)
data_index[data_index == "Hong Kong"] = "香港市"
data_values = prepared_data.values

plt.figure(figsize=(20, 8), dpi=80)
plt.barh(data_index, data_values)
plt.show()

你可能感兴趣的:(python)