第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何正確構(gòu)造具有單個(gè)出口的遞歸函數(shù)?

如何正確構(gòu)造具有單個(gè)出口的遞歸函數(shù)?

慕俠2389804 2023-12-29 09:55:25
我編寫了一個(gè)遞歸函數(shù)來增強(qiáng) pandas.DataFrame.describe。它將峰度和偏斜添加為行。它還創(chuàng)建了第二個(gè)描述表來轉(zhuǎn)置第一個(gè)描述表,以便您獲得匯總統(tǒng)計(jì)數(shù)據(jù)的摘要。它工作得很好,只是我不喜歡編寫具有多個(gè)出口的函數(shù)。我嘗試用一個(gè) return 語(yǔ)句編寫它(請(qǐng)參閱注釋掉的部分),但它會(huì)在一個(gè)表中創(chuàng)建兩個(gè)轉(zhuǎn)置表。正確,但太多了。def get_better_desc(df, recursions: int = 1):    '''Adds kurtosis and skew to pandas.DataFrame.describe output. And, creates    second transposed version of this table called on itself for summary stats    of summary stats.    Parameters:        df: pandas.DataFrame, or Series but its super_desc isn't so meaningful.        recursions: integer number of times to apply recursively to create            super_desc. Default value of 1 is all that is necessary.    Returns:        better_desc: pandas.Dataframe (or Series) with kurtosis and skew added.        super_desc: pandas.DataFrame (or Series) of better_desc transposed and            made into a better_desc itself.'''        kurt = df.kurtosis()    kurt.name = 'kurt'    skew = df.skew()    skew.name = 'skew'    better_desc = df.describe().append([kurt, skew])        if recursions > 0:        super_desc = get_better_desc(better_desc.transpose(),                                     recursions=(recursions - 1))        return better_desc, super_desc    else:        return better_desc#     if recursions > 0:#         super_desc = get_better_desc(better_desc.transpose(),#                                      recursions=(recursions - 1))#     else:#         super_desc = better_desc    #     return better_desc, super_desc
查看完整描述

1 回答

?
陪伴而非守候

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超8個(gè)贊

該函數(shù)返回兩個(gè)數(shù)據(jù)幀,如果您只將其分配給一個(gè)變量,而不是忽略第二個(gè)返回值,它會(huì)將兩者分配給該變量。在遞歸調(diào)用中,您只需指定第一個(gè)表,即 returns 列表中的第一個(gè)元素[0]。


...

if recursions > 0:

        super_desc = get_better_desc(better_desc.transpose(),

                                     recursions=(recursions - 1))[0] #<=

    else:

        super_desc = better_desc

    

    return better_desc, super_desc


查看完整回答
反對(duì) 回復(fù) 2023-12-29
  • 1 回答
  • 0 關(guān)注
  • 137 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)