Python -- 操作Excel

1. 读取Excel

import logging

import pandas as pd

logger = logging.getLogger('django')

RoomNameIndex = 0
HomeOwnerNameIndex = 1
IdNumberIndex = 2

all_dict = {}


def add_port():
    res = pd.read_excel("C:\\Users\\99283\\Desktop\\云交付预约名单(3).xlsx", sheet_name="无限制")
    infodata = pd.DataFrame(res).values
    for i in infodata:
        if isinstance(i[5], str):
            if i[5] not in all_dict:
                all_dict[i[5]] = set()
                if ";" in i[1]:
                    owner_name = i[1].split(";")
                    for y in range(len(owner_name)):
                        all_dict[i[5]].add(str(i[IdNumberIndex + y]).strip())
                else:
                    all_dict[i[5]].add(i[2])
            else:
                if ";" in i[1]:
                    for y in range(len(i[1].split(";"))):
                        all_dict[i[5]].add(str(i[IdNumberIndex + y]).strip())
                else:
                    all_dict[i[5]].add(i[2])

    all_pe = 0
    for k, v in all_dict.items():
        all_pe += len(v)
        # print(k, v)
        print(k, ":>>>>", len(v))
    print(all_pe)


if __name__ == '__main__':
    add_port()

posted @ 2023-12-26 17:47  河图s  阅读(14)  评论(0)    收藏  举报