[英]How to return variables to multiple methods at once?
我能夠將多個變量返回給一個方法:
def groupby(self, df, groupbyvalue, fieldstoaggregate):
datamin = df.loc[df.groupby([groupbyvalue])[fieldstoaggregate].idxmin()]
datamax = df.loc[df.groupby([groupbyvalue])[fieldstoaggregate].idxmax()]
return plotsview.weatherplot(self, datamin, datamax)
是否可以一次將相同的datmin, datamax
返回到另一種方法?
作為:
return plotsview.newplot(self, datamin, datamax)
我將它們返回到以下方法:
class plotsview:
def weatherplot(self, datamax1, datamin1):
和
class plotsviewnew:
def newplot(self, datamax, datamin):
如果你想返回 2 個值,你可以返回一個元組。 只需將您的值計算為變量,然后返回它們:
def groupby(self, df, groupbyvalue, fieldstoaggregate):
datamin = df.loc[df.groupby([groupbyvalue])[fieldstoaggregate].idxmin()]
datamax = df.loc[df.groupby([groupbyvalue])[fieldstoaggregate].idxmax()]
weather_res = plotsview.weatherplot(self,datamin,datamax)
new_res = plotsview.newplot(self,datamin,datamax)
return weather_res, new_res
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.