已经解决啦(recipe 循环以后, dfPeakAll会根据recipeList的数目有多个dfPeakAll, 想返回多个recipe 的dfPeakAll 要怎么操作呢?)
def peak_search_recipe(df,WavelengthAvgCol,peaksearchdir,recipeList,infoCol):
wavelenth_temp = pd.DataFrame(columns = WavelengthAvgCol)
rt=[]
for recipe in recipeList:
dfData = df[df['Process recipe']== recipe].reset_index(drop= True)
waferNoList = dfData['PJID_Slot'].tolist()
dfDataInfo = dfData[infoCol]
dfPeakV = dfDataInfo.copy()# dfPeakV[i] change will cause dfDataInfo change
for waferNo in waferNoList:
dfChamberStepWafer = (dfData[dfData['PJID_Slot'] == waferNo].loc[:,WavelengthAvgCol])#.to_numpy()[0]# Transfer to 1 D
dfChamberStepPeaks, _= find_peaks(dfChamberStepWafer.to_numpy()[0], distance=10)
dfChamberStep = dfData[dfData['PJID_Slot'] == waferNo].loc[:,WavelengthAvgCol]
select_wave = dfChamberStep.iloc[:,dfChamberStepPeaks].reset_index(drop = True)
select_wave['PJID_Slot'] = waferNo
wavelenth_temp = pd.concat([wavelenth_temp,select_wave])#.reset_index()
KeyWavelenth = wavelenth_temp.dropna(how='all', axis = 1).reset_index(drop = True)
dfKeyWavelenth = pd.merge(dfDataInfo,KeyWavelenth, on ='PJID_Slot').reset_index(drop= True)
KeyWaveCount = dfKeyWavelenth[dfKeyWavelenth.columns[dfKeyWavelenth.columns.str.contains('Step10_.*nm_Avg',regex=True)]].notnull().sum()
waveFull = dfKeyWavelenth[ KeyWaveCount[KeyWaveCount.values == dfKeyWavelenth.shape[0]].index]#series1[series1.values == 1].index
waveNull = dfKeyWavelenth[KeyWaveCount[(dfKeyWavelenth.shape[0]/3 < KeyWaveCount.values)&( KeyWaveCount.values< dfKeyWavelenth.shape[0])].index]
for i in waveNull.columns:
#i = waveNull.columns[0]
dfPeakV[i] = dfData.iloc[:,dfData.columns.get_loc(i)-4:dfData.columns.get_loc(i)+4].max(axis = 1)
dfPeakAll = pd.concat([dfPeakV,waveFull], axis =1)
pd.concat([dfPeakV,waveFull], axis =1).shape
#pd.DataFrame(np.nansum(np.array(dfrecipe[['Step10_218.5nm_Avg','Step10_219.0nm_Avg']]),axis=1))
dfPeakAll.to_csv(os.path.join(peaksearchdir,recipe.split('/')[-1] + ' Wavelength Peak Full Rev.02.csv'), index = False)
rt.append([dfPeakAll])
return rt
你要保证每个dfPeakAll是相互隔离的。
另外python允许返回列表或者元组,只要你能获取到多个dfPeakAll,就可以返回,这仅仅是具体逻辑上处理的问题,比如
只要和函数调用方有合理的约定,返回多个应该没有什么问题啊。