我是靠谱客的博主 温暖水池,最近开发中收集的这篇文章主要介绍读取excel dataframe split 写入excel,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

import pandas as pd
import os
import copy
import shutil
import re
import xlrd, xlwt
from xlutils.copy import copy as xl_copy
from openpyxl import load_workbook
import numpy as np
def getInfoOfDigtalChannel(path):
# 去除首字母D, =.=
getInfo = pd.read_excel(path, sheet_name=Digital, dtype=str, keep_default_na=False, header=1)
info = pd.DataFrame(getInfo.iloc[:, :])
if info.empty:
print('file is empty')
else:
for i in range(0, info.keys().size):
if re.search('DUT.*Channel', info.keys()[i]):
for j in range(0, len(info)):
# print(re.split('^D',str(info.iat[j, i]))[-1])
info.iat[j, i] = re.split('^D', str(info.iat[j, i]))[-1]
# print(info.iat[j, i])
fileTo = os.path.join(OutputPath, 'channel_map_'+Digital+'.xlsx')
info.to_excel(fileTo, header=1, index=False, encoding='utf-8', sheet_name=Digital)
def getInfoOfDPSChannel(path):
# 去除首字母D, =.=
getInfo = pd.read_excel(path, sheet_name=Power, dtype=str, keep_default_na=False, header=1)
info = pd.DataFrame(getInfo.iloc[:, :])
if info.empty:
print('file is empty')
else:
print('file is not empty')
for i in range(0, info.keys().size):
if re.search('DUT.*Channel', info.keys()[i]):
for j in range(0, len(info)):
m = re.split('_P', str(info.iat[j, i]))[0]
n = re.split('_P', str(info.iat[j, i]))[-1]
if (re.search('-P', n)):
p = re.findall('(.*?)-P', n)[0]
q = re.split('-P', n)[-1]
if (len(p) == 1):
p = '0' + p
if (len(q) == 1):
q = '0' + q
info.iat[j, i] = m + p + '-' + m + q
else:
if (len(n) == 1):
n = '0' + n
info.iat[j, i] = m + n
fileTo = os.path.join(OutputPath, 'channel_map_'+Power+'.xlsx')
info.to_excel(fileTo, header=1, index=False, encoding='utf-8', sheet_name=Power)
def getInfoOfUtlityChannel(path):
getInfo = pd.read_excel(path, sheet_name=Utility, dtype=str, keep_default_na=False, header=1)
info = pd.DataFrame(getInfo.iloc[:, :])
if info.empty:
print('file is empty')
else:
print('file is not empty')
for i in range(0, info.keys().size):
for j in range(0, len(info)):
if re.search('_URW', info.iat[j, i]):
# print(str(info.iat[j, i]))
x = re.findall('UB(.*?)_URW', str(info.iat[j, i]))[0]
y = re.split('_URW', str(info.iat[j, i]))[-1]
if re.search('^0', y) and re.search('^((?!09).)*$', y):
y = '0' + str(int(y) + 1)
# print(y)
if re.search('^1d', y) or re.search('09', y):
y = str(int(y) + 1)
# print("y---", y)
z = 'UT'+ x + y
info.iat[j, i] = z
fileTo = os.path.join(OutputPath, 'channel_map_'+Utility+'.xlsx')
info.to_excel(fileTo, header=1, index=False, encoding='utf-8', sheet_name=Utility)
Digital = '1826S_IO'
Power = '1826_PG'
Utility = 'CTRL'
path = os.path.join(os.getcwd(), 'input\map.xlsx')
OutputPath = os.path.join(os.getcwd(), 'output')
# 判断是否存在output文件夹
if (os.path.exists(OutputPath)):
shutil.rmtree(OutputPath)
print('output dir has been rm -rf and new makedirs')
os.makedirs(OutputPath)
getInfoOfDigtalChannel(path)
getInfoOfDPSChannel(path)
getInfoOfUtlityChannel(path)

最后

以上就是温暖水池为你收集整理的读取excel dataframe split 写入excel的全部内容,希望文章能够帮你解决读取excel dataframe split 写入excel所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(90)

评论列表共有 0 条评论

立即
投稿
返回
顶部