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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Pandas DataFrame 創(chuàng)建三個新列

使用 Pandas DataFrame 創(chuàng)建三個新列

人到中年有點甜 2021-06-13 08:22:03
我在下面有一個數(shù)據(jù)框,并嘗試創(chuàng)建更大、更少和計數(shù)的三個新列。條件是計算有多少值大于/小于平均值并將它們相加。df =             APPL       Std_1       Std_2       Std_3          Mean       0   ACCMGR      106.8754    130.1600    107.1861    114.750510       1   ACCOUNTS    121.7034    113.4927    114.5482    116.581458       2   AUTH        116.8585    112.4487    115.2700    114.859050def make_count(comp_cols, mean_col):    count_d = {'greater': 0, 'less': 0}    for col in comp_cols:        if col > mean_col:            count_d['greater'] += 1        elif col < mean_col:            count_d['less'] += 1    return count_d['greater'], count_d['less'], (count_d['greater'] + count_d['less'])def apply_make_count(df):    a,b,c,*d= df.apply(lambda row: make_count([row['Std_1'], row['Std_2'], row['Std_3']], row['Mean of Std']), axis=1)    df['greater'],df['less'],df['count']=a,b,capply_make_count(df)但我得到了錯誤顯示:13     df['greater'],df['less'],df['count']=list(zip(a,b,c))ValueError: Length of values does not match length of index我想成為的輸出 df =     APPL       Std_1       Std_2       Std_3      Mean  greater less    count0   ACCMGR      106.8754    130.1600    107.1861    114.750510        1    2        31   ACCOUNTS    121.7034    113.4927    114.5482    116.581458        1    2        32   AUTH        116.8585    112.4487    115.2700    114.859050        2    1        3
查看完整描述

3 回答

?
哈士奇WWW

TA貢獻1799條經(jīng)驗 獲得超6個贊

嘗試


df['greater'] = (df.iloc[:, 1:4].values > df[['Mean']].values).sum(axis=1)


df['less'] = (df.iloc[:, 1:4].values < df[['Mean']].values).sum(axis=1)


df['count'] = df.iloc[:, 1:4].count(1)



    APPL        Std_1       Std_2       Std_3       Mean       greater  less    count

0   ACCMGR      106.8754    130.1600    107.1861    114.750510  1       2       3

1   ACCOUNTS    121.7034    113.4927    114.5482    116.581458  1       2       3

2   AUTH        116.8585    112.4487    115.2700    114.859050  2       1       3


查看完整回答
反對 回復(fù) 2021-06-16
  • 3 回答
  • 0 關(guān)注
  • 362 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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