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

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

我怎樣才能得到負(fù)數(shù)百分比和最負(fù)數(shù)排序?

我怎樣才能得到負(fù)數(shù)百分比和最負(fù)數(shù)排序?

胡子哥哥 2022-07-26 10:18:12
我想出了一種方法來進(jìn)行分組并根據(jù)兩個(gè)字段獲取計(jì)數(shù):df.groupby(['brand','result']).size()df.groupby(['brand','result']).count()這會(huì)產(chǎn)生相同的結(jié)果。我的數(shù)據(jù)現(xiàn)在看起來像這樣。Johnson's Baby Powder   negative         21                          neutral          5                          positive         121Estee Lauder            negative         7                          positive         23Calvin Klein            negative         10                          neutral          3                          positive         29 我想得到每個(gè)品牌的結(jié)果百分比,就像這樣。Johnson's Baby Powder   negative    21  0.142857143                        neutral     5   0.034013605                        positive    121 0.823129252Estee Lauder            negative    7   0.233333333                        positive    23  0.766666667Calvin Klein            negative    10  0.238095238                        neutral     3   0.071428571                        positive    29  0.69047619不過,最終,我只想顯示“結(jié)果”負(fù)值 > 20% 的“品牌”。所以,我想看看這個(gè)(以及其他符合業(yè)務(wù)邏輯規(guī)則的品牌)。Estee Lauder            negative    7   0.233333333                        positive    23  0.766666667我怎樣才能做到這一點(diǎn)?
查看完整描述

2 回答

?
搖曳的薔薇

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

嘗試


x = df.groupby(['brand'])['result'].value_counts(normalize=True)

樣本數(shù)據(jù)輸出


>>> y = x.loc[(x.index.get_level_values(1) == 'negative')]


>>> y[y>0.2]

airline         airline_sentiment

American        negative             0.710402

Delta           negative             0.429793

Southwest       negative             0.490083

US Airways      negative             0.776862

United          negative             0.688906

Virgin America  negative             0.359127

Name: airline_sentiment, dtype: float64


>>> y[y>0.2].index.get_level_values(0)

Index(['American', 'Delta', 'Southwest', 'US Airways', 'United',

       'Virgin America'],

      dtype='object', name='airline')


查看完整回答
反對(duì) 回復(fù) 2022-07-26
?
收到一只叮咚

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

添加到@Vishnudev 的答案,使用:


print(df[df.groupby(['brand'])['result'].value_counts(normalize=True).ge(0.5).tolist()])

輸出:


          brand    result  number

3  Estee Lauder  negative       7

4  Estee Lauder  positive      23


查看完整回答
反對(duì) 回復(fù) 2022-07-26
  • 2 回答
  • 0 關(guān)注
  • 65 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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