Ошибка памяти Python / Pandas с несколькими файлами Excel - PullRequest
0 голосов
/ 03 февраля 2019

Я новичок в Python.

Недавно я собрал достаточно смелости, чтобы написать небольшой скрипт для чтения нескольких файлов Excel, копирования и преобразования определенных частей содержимого, подготовки пары таблиц из данных.в нем, а затем скомпилировать их в один файл, и сделать несколько графиков с окончательными кадрами данных.В основном код, который я написал, делает все, что я хочу, но только для нескольких файлов Excel.Однако, если у меня есть, скажем, 15 файлов Excel, он просто выходит из памяти.

Я пометил различные разделы моего кода.Итак,

В первом разделе - это все объявления и инициализации, импорт пакетов и прочее.

В разделе 2 я инициализирую около 23 фреймов данных, которые являются параметрами, данные которых необходимо извлечь из разныхчасти входных файлов Excel.

В разделе 3 - у меня есть набор функций, которые преобразуют данные из каждого файла.Они вызываются в следующем разделе - разделе 4, который в основном является циклом for, который перебирает все файлы в папке, которую выбирает пользователь, и заполняет 23 нечетных кадра данных, которые я инициализирую в разделе 2, преобразованными данными.

РАЗДЕЛ 5: Здесь мне нужна помощь.После того, как все кадры данных параметров заполнены необходимыми мне данными, я начинаю записывать их один за другим с помощью обработчика Excel Writer, который я объявил в первом разделе.Теперь мне нужны данные каждого параметра на отдельных листах окончательного файла Excel, а затем мне нужен один лист со всеми ними.Я использую dataframe comp, чтобы объединить каждый параметр dataframe с ним, как только я передам параметр dataframe в Excel Writer.

Слияние и все идет хорошо.По сути, этот код выполняет ту работу, которую я хочу, но только для нескольких файлов Excel.Однако, если у меня есть, скажем, 15 файлов Excel, он просто уходит в память после того, как несколько параметров объединены в файл данных comp.Я попытался удалить каждый параметр dataframe после слияния его с comp, как вы можете видеть ниже с помощью операторов del.Но даже это не делает меня намного дальше.

Я получаю следующую ошибку, говорящую об ошибке памяти:

Traceback (most recent call last):

  File "<ipython-input-3-f60f33c72739>", line 1, in <module>
    runfile('C:/Users/spoikayi/Documents/SpecComp v2/functioned-expansion-v4-memoryoptimisation.py', wdir='C:/Users/spoikayi/Documents/SpecComp v2')

  File "C:\Users\spoikayi\Documents\Portables\Anaconda\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 668, in runfile
    execfile(filename, namespace)

  File "C:\Users\spoikayi\Documents\Portables\Anaconda\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/spoikayi/Documents/SpecComp v2/functioned-expansion-v4-memoryoptimisation.py", line 308, in <module>
    comp = comp.merge(M32DICDsheet,how='left',on=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID'],)

  File "C:\Users\spoikayi\Documents\Portables\Anaconda\anaconda3\lib\site-packages\pandas\core\frame.py", line 6389, in merge
    copy=copy, indicator=indicator, validate=validate)

  File "C:\Users\spoikayi\Documents\Portables\Anaconda\anaconda3\lib\site-packages\pandas\core\reshape\merge.py", line 62, in merge
    return op.get_result()

  File "C:\Users\spoikayi\Documents\Portables\Anaconda\anaconda3\lib\site-packages\pandas\core\reshape\merge.py", line 582, in get_result
    concat_axis=0, copy=self.copy)

  File "C:\Users\spoikayi\Documents\Portables\Anaconda\anaconda3\lib\site-packages\pandas\core\internals.py", line 5421, in concatenate_block_managers
    concatenate_join_units(join_units, concat_axis, copy=copy),

  File "C:\Users\spoikayi\Documents\Portables\Anaconda\anaconda3\lib\site-packages\pandas\core\internals.py", line 5575, in concatenate_join_units
    concat_values = concat_values.copy()

MemoryError

ЗДЕСЬ МОЙ КОД:

**#SECTION1 - IMPORT PKGs DECLARE GLOBAL VARIABLES ETC.**

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import shutil
import os
import glob
import tkinter as tk
from tkinter import filedialog
from tkinter import messagebox
from tkinter import ttk

root = tk.Tk()
cwd = os.getcwd()
root.lift()
pb = ttk.Progressbar(root,orient ="horizontal",length = 200, mode ="indeterminate")
root.withdraw()
thisdir = filedialog.askdirectory(parent=root, initialdir="/",
                                    title='Please select a directory with the Spectrometer excel files')

root.lift()
#thisdir=r'C:\Users\spoikayi\OneDrive - Teledyne Technologies Inc\TEMP_DOCS\NXP\UHAST Failure\Matthieu data extraction req\Input Spectrometer'
os.chdir(thisdir)
outdir=thisdir+'/SpeCompOutput'
outfile=outdir+'/SpeCompOutput.xlsx'
FileList = glob.glob('*.xlsx')
print("You have following files in the target folder:\n")
msg="You have following files in the target folder:\n"
for i in FileList:
    msg=msg+i+"\n"
    print (i,'\n')
msg=msg+"""Make sure they are not open in excel at present.
Make sure all files in the folder are spectrometer output files.
This program will take only .xlsx files.
If you rerun this program, it will delete the PREVIOUS result folder
Happy Analysis!
            -SHARATH"""


root.lift()
messagebox.showerror("IMPORTANT!", msg)
root.lift()


writer = pd.ExcelWriter(outfile)
spedf = pd.DataFrame([])
pairingdf2=pd.DataFrame([])
comp=pd.DataFrame([])

"""SECTION 2-declare parameters - each dataframe beow is a paramter 
i want to extract from each excel file. 
SO each of them finally becomes a dataframe few 100 rows by six columns"""

M32FinCDsheet=pd.DataFrame([])
M32DICDsheet=pd.DataFrame([])
TSVFinCDsheet=pd.DataFrame([])
TSV_M94_Depth=pd.DataFrame([])
TSV_Liner_thk=pd.DataFrame([])
TSV_Poly_thk=pd.DataFrame([])
TSV_Etch_Depth=pd.DataFrame([])
TSV_M77_Al_Thk=pd.DataFrame([])
M35_Ox_Thk=pd.DataFrame([])
M35_Fin_CD=pd.DataFrame([])
M36_Ox_Thk=pd.DataFrame([])
M36_Fin_CD=pd.DataFrame([])
M30_Fin_CD=pd.DataFrame([])
M31_Fin_CD=pd.DataFrame([])
M31_TEOS_DepThk=pd.DataFrame([])
M31_TEOS_CMP=pd.DataFrame([])
MEMBRANE_Thk_CMP=pd.DataFrame([])
MEMS_M70_Ge_Thk=pd.DataFrame([])
M32_TEOS_Thk=pd.DataFrame([])
VHF_LRED=pd.DataFrame([])
CAP_Thk=pd.DataFrame([])
FINAL_BOW=pd.DataFrame([])
FINAL_WARP=pd.DataFrame([])

"""
SECTION 3 - These functions wrangle out data from different parts of the input excel files , fills up the dataframes initialized above, etc. """


#fsheet_DCOP, gives us DCOP_data appended to pairing gives us DCOP_table, the table is transposed and iterated to give the DCOP_sheet.
def printLog(*args, **kwargs):
            print(*args, **kwargs)
            with open('SpeCompErrorLog.txt','a') as file:
                print(*args, **kwargs, file=file)


def fsheet_DCOP(s,j,k,l):
    #from the input frame j it returns the column that matches DCOP name k in column 5 and parameter name l in column 7
    ret=pd.DataFrame([])
    j=j[j[3].str.contains(s,na=False)]
    for i in k:
        ret=ret.append(j[j[5] == i])    
    ret=ret[ret[7]==l]
    ret=ret[:1] #Alert!!!!!!
    if(ret.empty):
                printLog(i,"Empty\nFeed NaN",ret)
                ret=pd.DataFrame(np.nan, index=[0], columns=[0,24])

    return ret

def fsheet_Table(j,k):
    j=j.transpose()
    j=j[5:]
    j.columns=[k]
    j=j.transpose()
    ret=wfrpair.append(j)
    ret=ret.iloc[:,5:30]
    ret = ret.transpose()
    return ret

def fin_col_ren(j,k):
    j.columns=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID',k]
    j=j.infer_objects() #infer column datatypes and aassign them so that merge doesnt fail due to type mismatch.
    return j

def extractor(fsheet,s,j,k,l):
    r=pd.DataFrame([])
    p=fsheet_DCOP(s,fsheet,j,k)
    q=fsheet_Table(p,l)
    r=r.append(q)
    return r

def boxplot(x_data, y_data, base_color="#539caf", median_color="#297083", x_label="", y_label="", title=""):
    _, ax = plt.subplots()

    # Draw boxplots, specifying desired style
    ax.boxplot(y_data
               # patch_artist must be True to control box fill
               , patch_artist = True
               # Properties of median line
               , medianprops = {'color': median_color}
               # Properties of box
               , boxprops = {'color': base_color, 'facecolor': base_color}
               # Properties of whiskers
               , whiskerprops = {'color': base_color}
               # Properties of whisker caps
               , capprops = {'color': base_color})

    # By default, the tick label starts at 1 and increments by 1 for
    # each box drawn. This sets the labels to the ones we want
    ax.set_xticklabels(x_data)
    ax.set_ylabel(y_label)
    ax.set_xlabel(x_label)
    ax.set_title(title)

"""
SECTION 4: this for loop basically iterates through all the files in the folder selected by a user, and then calls those functions above and finally fills all those parameters dataframes with the data we need
"""

for i in FileList:
    fullsheet = pd.read_excel(i, sheet_name='Sheet1')
    fsheet = pd.read_excel(i, sheet_name='Sheet1',header=None)
    fsheet=fsheet.drop([0,1,2,3,4,5],axis=0)
    fsheet=fsheet.drop(columns=[0,1,2,8,9,10,11,12,13,14,15,16,42,43])
    wfrpair=fsheet.iloc[0:6]
    pairing=fullsheet.iloc[5:11,17:39]
    spe=fullsheet.iloc[[5,6,7,8,9,10,11,14,15,16,17,18,19,20],[17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39]]
    pairing=pairing.transpose()
    spe=spe.transpose()
    spedf=spedf.append(spe)
    pairingdf2=pairingdf2.append(pairing)


    df1y632=fsheet_DCOP('M32',fsheet,['1Y632'],'Moyenne tr CD Finale-Item')
    dfTSV=fsheet_DCOP('M17',fsheet,['1L417','1V417'],'Moyenne tr CD Finale-Item')
    M32data=fsheet_Table(df1y632,'M32_Fin_CD')
    TSVCDdata=fsheet_Table(dfTSV,'TSV_CD')
    M32FinCDsheet=M32FinCDsheet.append(M32data)
    TSVFinCDsheet=TSVFinCDsheet.append(TSVCDdata)


    TSV_M94_Depth=TSV_M94_Depth.append(extractor(fsheet,'M94',['EA1_MESURE_Z_FIN_M94'],'Moyenne','TSV_M94_Depth'))
    TSV_Liner_thk=TSV_Liner_thk.append(extractor(fsheet,'M17',['3D447'],"Epaisseur d'oxyde-Item",'TSV_Liner_Ox_Thk'))
    TSV_Poly_thk=TSV_Poly_thk.append(extractor(fsheet,'M17',['EA1_MESURE_FILM_ISDP_DEPOT_M17'],'Moyenne','TSV_ISDP_Thk'))
    TSV_Etch_Depth=TSV_Etch_Depth.append(extractor(fsheet,'M17',['EA1_MESURE_Z_GRAV_M17'],'Moyenne','TSV_Etch_Depth'))
    TSV_M77_Al_Thk=TSV_M77_Al_Thk.append(extractor(fsheet,'M77',['5D700','5D870'],'Epaisseur du FILM.-Calc','M77_Al_Thk'))
    M35_Ox_Thk=M35_Ox_Thk.append(extractor(fsheet,'M35',['3D412'],"Epaisseur d'oxyde-Item",'M35_Ox_Thk'))
    M35_Fin_CD=M35_Fin_CD.append(extractor(fsheet,'M35',['1V635'],'Moyenne tr CD Finale-Item','M35_Fin_CD'))
    M36_Ox_Thk=M36_Ox_Thk.append(extractor(fsheet,'M36',['3D412'],"Epaisseur d'oxyde-Item",'M36_Ox_Thk'))
    M36_Fin_CD=M36_Fin_CD.append(extractor(fsheet,'M36',['1V636'],'Moyenne tr CD Finale-Item','M36_Fin_CD'))
    M30_Fin_CD=M30_Fin_CD.append(extractor(fsheet,'M30',['1L430','1V430'],'Moyenne tr CD Finale-Item','M30_Fin_CD'))
    M31_Fin_CD=M31_Fin_CD.append(extractor(fsheet,'M31',['1L431','1V431'],'Moyenne tr CD Finale-Item','M31_Fin_CD'))
    M31_TEOS_DepThk=M31_TEOS_DepThk.append(extractor(fsheet,'M31',['EA1_MESURE_FILM_TEOS_LPCVD_DEPOT_M31'],'Moyenne','M31_TEOS_DepThk'))
    M31_TEOS_CMP=M31_TEOS_CMP.append(extractor(fsheet,'M31',['EA1_MESURE_FILM_TEOS_LPCVD_APCMP_M31'],'Moyenne','M31_TEOS_CMP'))
    M32DICDsheet=M32DICDsheet.append(extractor(fsheet,'M32',['1Y532'],'Moyenne tr CD Develop-Item','M32 Dev CD'))
    MEMBRANE_Thk_CMP=MEMBRANE_Thk_CMP.append(extractor(fsheet,'POLISSAGE1',['EA1_MESURE_FILM_MEMBRANE_POLISSAGE1_FIN'],'Moyenne','MEMBRANE_Thk'))
    MEMS_M70_Ge_Thk=MEMS_M70_Ge_Thk.append(extractor(fsheet,'M70',['5D615','5D850'],'Epaisseur du FILM.-Calc','Ge_Thk'))
    M32_TEOS_Thk=M32_TEOS_Thk.append(extractor(fsheet,'M32',['EA1_MESURE_FILM_TEOS_DEPOT_M32'],'Moyenne','M32_TEOS_Thk'))
    VHF_LRED=VHF_LRED.append(extractor(fsheet,'M32',['2QH02'],'Moyenne de Largeur-Calc','VHF_LRED'))
    CAP_Thk=CAP_Thk.append(extractor(fsheet,'POLISSAGE2',['EA1_MESURE_THKTTV_MEMBRANE_POLISSAGE2'],'Moyenne','CAP_Thk'))
    FINAL_BOW=FINAL_BOW.append(extractor(fsheet,'M60',['4K002'],'BOWBF-Item','FINAL_BOW'))
    FINAL_WARP=FINAL_WARP.append(extractor(fsheet,'M60',['4K002'],'WARPBF-Item','FINAL_WARP'))



spedf=spedf.drop(columns=[11,20])
spedf.columns=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID','VERTICAL GAP HEIGHT (M34)','MEMBRANE THICKNESS','SI GAP WIDTH (M32 FIN)','MEMBRANE TO ELECTRODE GAP','TOP CAVITY DEPTH (M94)','CONTACT ANGLE OF FOTS COATING']
pairingdf2.columns=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID']
spedf=spedf.infer_objects()
M32FinCDsheet=fin_col_ren(M32FinCDsheet,'M32 Fin CD 1Y632')
TSVFinCDsheet=fin_col_ren(TSVFinCDsheet,'TSV Fin CD')
comp = spedf.merge(TSVFinCDsheet,how='left',on=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID'],)

pairingdf2.to_excel(writer,sheet_name='Pairing')
spedf.to_excel(writer,sheet_name='SPE')
del(spedf)
del(pairingdf2)

"""
SECTION 5: This is where I need help.
Once I have all the parameter dataframes filled with the data I need,
I start to write them one by one with an  excel writer handler I had declared above .
Now, I need each of the paarameters data in separate sheets, and then I need a single sheet with all of them in it.
I am using the dataframe comp to merge each of the parameter dataframe to it, once I commit the parameter dataframe to the excel writer.

The merge and everything goes fine.
Basically this code does the work I want it to do, but only for few excel files.
However if I have, say 15 excel files, it just goes out of memory after few parameters are merged into the comp dataframe.
I tried deletting each parameter dataframe after merging it to comp as you can see below with the del statements.
But even that doesnt take me much farther.

"""

TSV_M94_Depth=fin_col_ren(TSV_M94_Depth,'TSV_M94_Depth')
comp = comp.merge(TSV_M94_Depth,how='left',on=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID'],)
TSV_M94_Depth.to_excel(writer,sheet_name='TSV_M94_Depth')
del(TSV_M94_Depth)
print('\n TSV_M94_Depth Committed \n')


TSV_Liner_thk=fin_col_ren(TSV_Liner_thk,'TSV_Liner_Ox_Thk')
comp = comp.merge(TSV_Liner_thk,how='left',on=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID'],)
TSV_Liner_thk.to_excel(writer,sheet_name='TSV_Liner_Ox_Thk')
del(TSV_Liner_thk)
print('\n TSV_Liner_thk Committed \n')


TSV_Poly_thk=fin_col_ren(TSV_Poly_thk,'TSV_ISDP_Thk')
comp = comp.merge(TSV_Poly_thk,how='left',on=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID'],)
TSV_Poly_thk.to_excel(writer,sheet_name='TSV_ISDP_Thk')
del(TSV_Poly_thk)

TSV_Etch_Depth=fin_col_ren(TSV_Etch_Depth,'TSV_Etch_Depth')
comp = comp.merge(TSV_Etch_Depth,how='left',on=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID'],)
TSV_Etch_Depth.to_excel(writer,sheet_name='TSV_Etch_Depth')
del(TSV_Etch_Depth)

TSV_M77_Al_Thk=fin_col_ren(TSV_M77_Al_Thk,'M77_Al_Thk')
comp = comp.merge(TSV_M77_Al_Thk,how='left',on=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID'],)
TSV_M77_Al_Thk.to_excel(writer,sheet_name='TSV_M77_Al_Thk')
del(TSV_M77_Al_Thk)


M35_Ox_Thk=fin_col_ren(M35_Ox_Thk,'M35_Ox_Thk')
comp = comp.merge(M35_Ox_Thk,how='left',on=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID'],)
M35_Ox_Thk.to_excel(writer,sheet_name='M35_Ox_Thk')
del(M35_Ox_Thk)

M35_Fin_CD=fin_col_ren(M35_Fin_CD,'M35_Fin_CD')
comp = comp.merge(M35_Fin_CD,how='left',on=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID'],)
M35_Fin_CD.to_excel(writer,sheet_name='M35_Fin_CD')
del(M35_Fin_CD)

M36_Ox_Thk=fin_col_ren(M36_Ox_Thk,'M36_Ox_Thk')
comp = comp.merge(M36_Ox_Thk,how='left',on=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID'],)
M36_Ox_Thk.to_excel(writer,sheet_name='M36_Ox_Thk')
del(M36_Ox_Thk)


M36_Fin_CD=fin_col_ren(M36_Fin_CD,'M36_Fin_CD')
comp = comp.merge(M36_Fin_CD,how='left',on=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID'],)
M36_Fin_CD.to_excel(writer,sheet_name='M36_Fin_CD')
del(M36_Fin_CD)

M30_Fin_CD=fin_col_ren(M30_Fin_CD,'M30_Fin_CD')
comp = comp.merge(M30_Fin_CD,how='left',on=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID'],)
M30_Fin_CD.to_excel(writer,sheet_name='M30_Fin_CD')
del(M30_Fin_CD)

M31_Fin_CD=fin_col_ren(M31_Fin_CD,'M31_Fin_CD')
comp = comp.merge(M31_Fin_CD,how='left',on=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID'],)
M31_Fin_CD.to_excel(writer,sheet_name='M31_Fin_CD')
del(M31_Fin_CD)


M31_TEOS_DepThk=fin_col_ren(M31_TEOS_DepThk,'M31_TEOS_DepThk')
comp = comp.merge(M31_TEOS_DepThk,how='left',on=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID'],)
M31_TEOS_DepThk.to_excel(writer,sheet_name='M31_TEOS_DepThk')
del(M31_TEOS_DepThk)

M31_TEOS_CMP=fin_col_ren(M31_TEOS_CMP,'M31_TEOS_CMP')
comp = comp.merge(M31_TEOS_CMP,how='left',on=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID'],)
M31_TEOS_CMP.to_excel(writer,sheet_name='M31_TEOS_CMP')
del(M31_TEOS_CMP)

MEMBRANE_Thk_CMP=fin_col_ren(MEMBRANE_Thk_CMP,'MEMBRANE_Thickness')
comp = comp.merge(MEMBRANE_Thk_CMP,how='left',on=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID'],)
MEMBRANE_Thk_CMP.to_excel(writer,sheet_name='MEMBRANE_Thickness')
del(MEMBRANE_Thk_CMP)

MEMS_M70_Ge_Thk=fin_col_ren(MEMS_M70_Ge_Thk,'Ge_Thk')
comp = comp.merge(MEMS_M70_Ge_Thk,how='left',on=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID'],)
MEMS_M70_Ge_Thk.to_excel(writer,sheet_name='Ge_Thk')
del(MEMS_M70_Ge_Thk)


M32_TEOS_Thk=fin_col_ren(M32_TEOS_Thk,'M32_TEOS_Thk')
comp = comp.merge(M32_TEOS_Thk,how='left',on=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID'],)
M32_TEOS_Thk.to_excel(writer,sheet_name='M32_TEOS_Thk')
del(M32_TEOS_Thk)

M32DICDsheet=fin_col_ren(M32DICDsheet,'M32 Dev CD')
comp = comp.merge(M32DICDsheet,how='left',on=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID'],)
M32DICDsheet.to_excel(writer,sheet_name='M32 Dev CD')
del(M32DICDsheet)

VHF_LRED=fin_col_ren(VHF_LRED,'VHF_LRED')
comp = comp.merge(VHF_LRED,how='left',on=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID'],)
VHF_LRED.to_excel(writer,sheet_name='VHF_LRED')
del(VHF_LRED)

CAP_Thk=fin_col_ren(CAP_Thk,'CAP_Thk')
comp = comp.merge(CAP_Thk,how='left',on=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID'],)
CAP_Thk.to_excel(writer,sheet_name='CAP_Thk')
del(CAP_Thk)

FINAL_BOW=fin_col_ren(FINAL_BOW,'FINAL_BOW')
comp = comp.merge(FINAL_BOW,how='left',on=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID'],)
FINAL_BOW.to_excel(writer,sheet_name='FINAL_BOW')
del(FINAL_BOW)

FINAL_WARP=fin_col_ren(FINAL_WARP,'FINAL_WARP')
comp = comp.merge(FINAL_WARP,how='left',on=['MEMS Lot ID','MEMS Wfr ID','MEMBRANE Lot ID','MEMBRANE Wfr ID','TSV Lot ID','TSV Wfr ID'],)
FINAL_WARP.to_excel(writer,sheet_name='FINAL_WARP')
del(FINAL_WARP)


comp.to_excel(writer,sheet_name='Compilation')
M32FinCDsheet.to_excel(writer,sheet_name='M32 Fin CD 1Y632')
TSVFinCDsheet.to_excel(writer,sheet_name='TSV Fin CD')

#4-pass to excel writer with sheet name


if os.path.exists(outdir):
    shutil.rmtree(outdir)

os.makedirs(outdir)
writer.save()
print("COMPILATION FINISHED!WTHOUT ERRORS!")
printLog("to-prinlog: COMPILATION FINISHED WTHOUT ERRORS!")

root.lift()
messagebox.showerror("SUCCESS!", """WE COMPILED THE DATA SUCCESSFULLY!
                     THE OUTPUT IS PLACED IN THE FOLDER YOU SELECTED,
                     IN A FOLDER CALLED SpecCompOutput
                     LOOK FOR THE FILE SpecCompOutput.xlsx""")
#boxplot(TSV_M94_Depth["MEMS Lot ID"],TSV_M94_Depth["TSV_M94_Depth"])
#dfbp = sns.load_dataset(TSV_M94_Depth)
# Grouped boxplot

comp=comp.replace('NaN',0)
hcomp=list(comp)
os.chdir(outdir)
print("\nLOT  Parameters Box Plot Summary\n\n")
for i in hcomp[6:]:
    print(i,"\n")
    plt.figure(i)
    box=sns.boxplot(x="MEMS Lot ID", y=i,data=comp)
    box.set_xticklabels(box.get_xticklabels(), rotation=45, ha="right")
    fig=box.get_figure()
    img=i+'.jpg'
    fig.savefig(img, dpi=200, bbox_inches='tight') 
os.chdir(thisdir)
plt.close('all')
pb.destroy()
root.withdraw()
os.remove('SpeCompErrorLog.txt')
root.destroy()




Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...