pandas报电压U程序

import pandas as pd
import re
import xlrd

def get_str_Ulevel(i,h01_u):     #拿到'10kVⅠ'
    str_station_Ulevel_1 = re.findall('[\a-zA-Z0-9ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩ]+', h01_u['"descr"'].at[i])      #拿到['/10kVⅡ', 'AB']
    str_station_Ulevel_2 = str_station_Ulevel_1[0].split('/')       #拿到['', '10kVⅢ']
    str_station_Ulevel_3 = str_station_Ulevel_2[-1]     #拿到10kVⅠ
    return str_station_Ulevel_3

def get_str_stationname(i,h01_u):       #拿到'裕隆变'
    str_stationname = re.findall('[\u4e00-\u9fa5]+', h01_u['"descr"'].at[i])    #拿到['裕隆变', '10kVⅠ母线AB线电压']
    return str_stationname[0]

def new_sheet(h01_u):       #拿到合并后的表
    h01_u.insert(1, '"descr"', value='')        #插入描述列后得到新的h01_u,即合并后的表
    for j in h02_u.index:
        for i in h01_u.index:
            if h01_u['"id"'].at[i] == h02_u['"id"'].at[j]:
                h01_u['"descr"'].at[i] = h02_u['"descr"'].at[j]
    return h01_u

excel_h_u = pd.read_excel('C:/h_u.xlsx','附表5 母线电压波动率统计表')
h01_u = pd.read_excel('C:/01_u.xls')        #Toad导出原始数据
h02_u = pd.read_excel('C:/02_u.xls')        #Toad导出,为了找站名

h01_u = new_sheet(h01_u)
# h01_u.to_excel('C:/try.xls', index=0)
# pd.options.display.max_columns = 999
# print(h01_u.head())
# print(excel_h_u.head())
def fill(x1,x2):        #填内容用
    for j in range(x1, x2):
        for i in h01_u.index:
            if get_str_stationname(i, h01_u) in str(excel_h_u['变电站'].at[j]) and get_str_Ulevel(i, h01_u) in str(excel_h_u['母线名称'].at[j]):
                excel_h_u['月最大电压(kV)'].at[j] = h01_u['"m_max"'].at[i]
                excel_h_u['最大值发生时间'].at[j] = h01_u['"m_max_t"'].at[i]
                excel_h_u['月最小电压(kV)'].at[j] = h01_u['"m_min"'].at[i]
                excel_h_u['最小值发生时间'].at[j] = h01_u['"m_min_t"'].at[i]
                excel_h_u['平均电压(kV)'].at[j] = h01_u['"average"'].at[i]
                excel_h_u['运行时间(分钟)'].at[j] = h01_u['"regular_time"'].at[i]
                excel_h_u['越上限时间(分钟)'].at[j] = h01_u['"h_time"'].at[i]
                excel_h_u['越下限时间(分钟)'].at[j] = h01_u['"l_time"'].at[i]
                # print(excel_h_u['最大值发生时间'].at[j].dtype)
                # print(h01_u['"m_max_t"'].at[i].dtype)

excel_h_u['最大值发生时间'] = excel_h_u['最大值发生时间'].astype(str)
excel_h_u['最小值发生时间'] = excel_h_u['最小值发生时间'].astype(str)
# type(h01_u['最小值发生时间'])
# print(type(h01_u['月最大电压(kV)'].at[5]))
# print(excel_h_u.columns)
fill(0, 46)     #(表格-2,表格-1)
fill(47, 190)
fill(191, 247)

excel_h_u.to_excel('C:/h_u_out.xlsx', index=0)

# h01_u.to_excel('C:/try.xls')

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值