2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
import pandas ut pd *
import re *
import win32com.client ut win32
from win32com.client import constantes
import os *
import os.path ut osp *
#Read mensam
semita = os.getcwd ()
fp=osp.join(path,'fuck_demo.xlsx')
df=pd.read_excel(fp, header=1, usecols=['Vide numerum', 'nomen funis optici sectionis (finem A-B)'], nrows=72)# Ne obliviscaris nrows
df.set_index('Vide numerum',inplace=Verum) # Pone index
#Filter data
df_1=df[~df ['Cable sectionis nomen (finis A-B)']. str. contains('JT01')]
df_2=df[df['Cable sectionis nomen (finis A-B)']. str. contains('JT01')]
#Operatio referat df_2 data
reg=re.compile(r'(?<=()(.*?)(?=))')
pf=df_2.copy()
pf['Extract AB end']=pf['Cable section name (A-end-B end)']. str.
pf['Numerus cable nucleorum opticorum']=pf ['Cable sectionis opticae nomen (finis A-B)']. str.extract(r'(?:.*)(-d+)', expand=False)
pf = pf.iloc [ : : - 1 ] # inverso ordine , clavis
pf ['Numerus funis opticorum nucleorum'] = pf ['Numerus funis opticorum nucleorum']. repone('-', '', regex=Verum) #reponere.
#Mge
ls=[]
pro idx, versu in pf.iterrows():
strs_2 = row ['Cable section name (finem A-B)']
strs_3=row['Extract AB end']
strs_4=row['Number funis optical nucleorum']
si strs_3 in strs_2,
ls.append([idx, strs_3, strs_4))
lg = [] # Repono current item est aequalis ad priorem item nec pervenerunt usque ad proximum
lf = [] # at duo items ante et post non sunt aequales
for i in range(len(ls));
si ls[i][1]==ls[i-1][1] et ls[i][1]!=ls[i+1][1]:
lt=ls[i-1:i+2]
l1 = [] # Repono numeris
l2=[]#Store AB terminal
l3 = [] # Repono numerus funem optical metretas
for j in range(len(lt));
l1.append(lt[j][0])
l2.append(lt[j][1])
l3.append(lt[j][-1])
new_l1 = [min (l1), max (l1)] # Get ad minimum et maximum
new_l1 = map (sp, new_l1) # List elementa sunt divisi chordis
new_l2=list(set(l2))+list(set(l3))
res_1 = '-'. iungere (new_l1) # Vide numerum splicing
res_2 = '-'. join(new_l2)#AB finis optical funem core numerus splicing
res_3=list((res_1,res_2))#Convert to list
lg.append(res_3)
aliud;
l1=ls[i][0]# copia numeri
l2=ls[i][1]#store AB end
l3 = ls [i][-1] # Repono numerus funis optical nuclei
res_4=list((l1,l2,l3))
lf.append(res_4)
xh = [] # Vide numerum
ab=[]#ab fine
xs = [] numerus metretas
for k in range(len(lf));
l1=lf[k][0]# copia numerorum
l2=lf[k][1]#store AB end
l3=lf[k][-1]# Repono numerum funis optical nuclei
xh.append(l1)
ab.append(l2)
xs.append(l3)
#Regroup in paria
xh=[xh[x:x+2] pro x in range(0,len(xh),2)]
ab=[ab[x:x+2] pro x in range(0,len(ab),2)]
xs=[xs[x:x+2] pro x in range(0,len(xs),2)]
lm=[]
for n range(len(xh));
l1=list((min(xh[n]),max(xh[n])))
new_l1=map(str,l1)
l2=list(set(xs[n]))
l3=ab[n]+l2
res_1='-'. join(new_l1)
res_2='-'. join(l3)
lm.append([res_1,res_2))
final_list=lg+lm
#removeduplication
final_ls=[]
ad l in final_list:
si l non final_ls:
finall_ls.append(l)
#Recreate DataFrame secundum eventus album
df_3=pd.DataFrame(data=final_ls,columns=['Vide numerum','nomen funis sectionis optici (finem A-B)'])
df_3.set_index ( 'Vide numerum', stilla = verum, inplace = verum) # Vide numerum in columna ut index
#Splice funis optici sectioni sine JT et sectioni discursum cum JT
cf=pd.concat([df_1,df_3],axis=0)
'''
Bene est indicem iterum reponere, vel non reponere. Usquam, numerus lineae numerorum + 2 . innititur
'''
# pywin32Read mensam excel
#Run Excel progressio
conari:
excel_app = win32.gencache.EnsureDispatch('Excel.Application')
nisi:
conari:
win32.gencache.EnsureDispatch ( 'et.Application')
nisi:
win32.gencache.EnsureDispatch('ket.Application')
postremo;
excel_app.Visible = verus
excel_app.DisplayAlerts = Falsi
#Read requiratur columnas in mensa
workbook = excel_app.Workbooks.Open(fp)
officina = workbook.Worksheets ( 'list')
worksheet.Columns (III) .Insert ()
worksheet.Columns (IV). Insert ()
worksheet.Cells(2, 3).Value = 'Dtrahens numerum' # pone columnae nomen
officina.Cells(2, 4).Value = 'nomen paragraphum'# pone columnae nomen.
#Operation forma
pro idx, in cf.iterrows():
dl=row ['Cable section name (finem A-B)']
bh = idx
si '-' in str(bh);
sb=bh.split('-')
start_row = int (min(sb)) + II # Satus row numerus
end_row = int (max(sb)) +2# finis row numerus
range1_to_merge=worksheet.Range(worksheet.Cells(start_row, 3), worksheet.Cells(end_row, 3))
range2_to_merge=worksheet.Range(worksheet.Cells(start_row, 4), worksheet.Cells(end_row, 4))
range3_to_color=worksheet.Range(worksheet.Cells(start_row, 5), worksheet.Cells(end_row, 5))
range4_to_color=worksheet.Range(worksheet.Cells(start_row, 17), worksheet.Cells(end_row, 17))
range2_to_merge.WrapText = Verum # Automatarie involvent lineae
color
range4_to_color.Interior.Color = 7396243
#range3_to_merge.Font.Color = 25500 # Dark ruber text
range1_to_merge.Value = bh# Drawing number
range2_to_merge.Value = DL# Optical funem paragraph
range1_to_merge.Merge()
range2_to_merge.Merge()
range2_to_merge.Rows.RowHeight = XXXVI "
range2_to_merge.Columns.ColumnWidth = 34
aliud;
worksheet.Cells(idx+2,3).Value = idx
worksheet.Cells(idx+2,4).Value = dl*
worksheet.Cells (idx + 2,4). WrapText = Verum # Automatarie lineae involvent
#End operatio et forma nisi
workbook.Save ()
workbook.Close (SaveChanges = False)
excel_app.Quit()