Python日志_20211019_1631

统计中国各城市星巴克数量方法: 【Python日志_20211019_1631】(自行改动:把Hong Kong 改为香港市)

import numpy as np import pandas as pd from matplotlib import pyplot as pltplt.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 = https://www.it610.com/article/p1.sort_values(ascending=False)[:10]data_index = np.array(prepared_data.index) data_index[data_index =="Hong Kong"] = "香港市" data_values = prepared_data.valuesplt.figure(figsize=(20, 8), dpi=80) plt.barh(data_index, data_values) plt.show()

    推荐阅读