python操作excel表格根据sheet,并且把这列每项内容转换成大写首字母

# -*- coding:utf-8 -*-
import openpyxl
import pypinyin


wb = openpyxl.load_workbook(r"D:\PythonCode\AfterInstalled\爬取共享平台\人口库设计20200419.xlsx")
ws = wb.get_sheet_by_name('人口基准信息')


data_dict = {"nodes": [], "links": []}

for i in range(2, 50000):  # 获取很多行,中间程序有中断
    # xuqiu_bumen = ws.cell(row=i, column=3).value
    mulu = ws.cell(row=i, column=4).value
    # print(mulu)
    # print(mulu)
    if mulu == None:
        break
    a = pypinyin.pinyin(mulu, style=pypinyin.FIRST_LETTER)
    b = []
    for i in range(len(a)):
        b.append(str(a[i][0]).upper())
    c = ''.join(b)
    print(c)

 

posted @ 2020-04-22 23:46  learnacode  阅读(475)  评论(0编辑  收藏  举报