import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# 设置风格,seaborn有5种基本风格,context表示环境
sns.set(style="white", context="notebook")
# 处理中文问题
sns.set_style('whitegrid', {'font.sans-serif':['simhei', 'Arial']})


data = pd.read_csv('D:\\myfiles\\study\\python\\analyse\\数据团\\城市数据团_数据分析师_体验课_课程资料\\数据资料\\地市级党委书记数据库(2000-10).csv', encoding='gbk')
data_gender2 = data[['省级政区名称','性别']]
data_gender2_re = data_gender2[data_gender2['性别'].notnull()]
pt = pd.crosstab(data_gender2_re['省级政区名称'], data_gender2_re['性别'])
pt['女性占比'] =  pt['女'] / (pt['女'] + pt['男'])
pt2 = pt.sort_values(by = ['女性占比'], ascending = False)
x = ['Percentage of Women leaders_structure']
y = pt2['女性占比'].tolist()
# 设定x,y值

fig = plt.figure(figsize=(6,4))
sns.boxplot(data = y,palette="Greens")
plt.title('Percentage of Women leaders')
plt.ylabel('Per %')
# 数据可视化:箱型图

sns.despine(bottom=True)
plt.show()