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)

 

posted @ 2018-11-30 16:48  Element_01  阅读(1107)  评论(0编辑  收藏  举报