pandas 分析各地区男女的分布情况
import pandas as pd # 结构类似:{“南京”:{"男":12,“女”:33},} dic = {} data = pd.read_excel("./11.xlsx").as_matrix() for line in data: if line[1] not in dic: dic[line[1]] = {} if line[-1] not in dic[line[1]]: dic[line[1]][line[-1]] = {"男": 0, "女": 0} if line[-2] == "男": dic[line[1]][line[-1]]["男"] += 1 else: dic[line[1]][line[-1]]["女"] += 1 print(dic)